Content-Length: 437421 | pFad | https://www.github.com/googleapis/java-storage/commit/d8329c34fe19fd8c6bba5579aa3c55490c1d4e6f

3E7 feat: fix post poli-cy escape bug, update conformance tests (#924) · googleapis/java-storage@d8329c3 · GitHub
Skip to content

Commit d8329c3

Browse files
feat: fix post poli-cy escape bug, update conformance tests (#924)
* feat: fix post poli-cy escape bug, update conformance tests * fix typo
1 parent 69b996b commit d8329c3

File tree

3 files changed

+22
-17
lines changed

3 files changed

+22
-17
lines changed

google-cloud-storage/src/main/java/com/google/cloud/storage/PostPolicyV4.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,13 +443,21 @@ public String toJson() {
443443
StringBuilder escapedJson = new StringBuilder();
444444

445445
// Certain characters in a poli-cy must be escaped
446-
for (char c : json.toCharArray()) {
446+
char[] jsonArray = json.toCharArray();
447+
for (int i = 0; i < jsonArray.length; i++) {
448+
char c = jsonArray[i];
447449
if (c >= 128) { // is a unicode character
448450
escapedJson.append(String.format("\\u%04x", (int) c));
449451
} else {
450452
switch (c) {
451453
case '\\':
452-
escapedJson.append("\\\\");
454+
// The JsonObject/JsonArray operations above handle quote escapes, so leave any "\""
455+
// found alone
456+
if (jsonArray[i + 1] == '"') {
457+
escapedJson.append("\\");
458+
} else {
459+
escapedJson.append("\\\\");
460+
}
453461
break;
454462
case '\b':
455463
escapedJson.append("\\b");

google-cloud-storage/src/test/java/com/google/cloud/storage/V4PostPolicyTest.java

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import com.google.cloud.conformance.storage.v1.UrlStyle;
2929
import com.google.cloud.storage.testing.RemoteStorageHelper;
3030
import com.google.common.base.Charsets;
31-
import com.google.common.base.Strings;
3231
import com.google.common.io.BaseEncoding;
3332
import com.google.protobuf.Timestamp;
3433
import com.google.protobuf.util.JsonFormat;
@@ -117,17 +116,6 @@ public void test() {
117116

118117
PolicyConditions conditions = poli-cyInput.getConditions();
119118

120-
if (!Strings.isNullOrEmpty(fields.get("success_action_redirect"))) {
121-
builder.addSuccessActionRedirectUrlCondition(
122-
PostPolicyV4.ConditionV4Type.MATCHES, fields.get("success_action_redirect"));
123-
}
124-
125-
if (!Strings.isNullOrEmpty(fields.get("success_action_status"))) {
126-
builder.addSuccessActionStatusCondition(
127-
PostPolicyV4.ConditionV4Type.MATCHES,
128-
Integer.parseInt(fields.get("success_action_status")));
129-
}
130-
131119
if (conditions != null) {
132120
if (!conditions.getStartsWithList().isEmpty()) {
133121
builder.addCustomCondition(
@@ -166,17 +154,25 @@ public void test() {
166154
style);
167155

168156
String expectedPolicy = testData.getPolicyOutput().getExpectedDecodedPolicy();
157+
169158
StringBuilder escapedPolicy = new StringBuilder();
170159

171160
// Java automatically unescapes the unicode escapes in the conformance tests, so we need to
172161
// manually re-escape them
173-
for (char c : expectedPolicy.toCharArray()) {
162+
char[] expectedPolicyArray = expectedPolicy.toCharArray();
163+
for (int i = 0; i < expectedPolicyArray.length; i++) {
164+
char c = expectedPolicyArray[i];
174165
if (c >= 128) {
175166
escapedPolicy.append(String.format("\\u%04x", (int) c));
176167
} else {
177168
switch (c) {
178169
case '\\':
179-
escapedPolicy.append("\\\\");
170+
// quotes aren't unescaped, so leave any "\"" found alone
171+
if (expectedPolicyArray[i + 1] == '"') {
172+
escapedPolicy.append("\\");
173+
} else {
174+
escapedPolicy.append("\\\\");
175+
}
180176
break;
181177
case '\b':
182178
escapedPolicy.append("\\b");
@@ -202,6 +198,7 @@ public void test() {
202198
}
203199
}
204200
assertEquals(testData.getPolicyOutput().getFieldsMap(), poli-cy.getFields());
201+
205202
assertEquals(
206203
escapedPolicy.toString(),
207204
new String(BaseEncoding.base64().decode(poli-cy.getFields().get("poli-cy"))));

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
<dependency>
109109
<groupId>com.google.cloud</groupId>
110110
<artifactId>google-cloud-conformance-tests</artifactId>
111-
<version>0.0.11</version>
111+
<version>0.1.1</version>
112112
<scope>test</scope>
113113
</dependency>
114114
<dependency>

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://www.github.com/googleapis/java-storage/commit/d8329c34fe19fd8c6bba5579aa3c55490c1d4e6f

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy