Skip to content

Commit eee15b9

Browse files
authored
Merge pull request #59 from EMCECS/bugfix-double-slash
fixed double-slash normalization
2 parents 43fea73 + ac91f40 commit eee15b9

File tree

3 files changed

+25
-22
lines changed

3 files changed

+25
-22
lines changed

build.gradle

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,15 @@ repositories {
5959
}
6060

6161
dependencies {
62-
implementation 'com.emc.ecs:smart-client:2.3.2',
63-
'com.emc.ecs:object-transform:1.1.0',
64-
'commons-codec:commons-codec:1.15',
65-
'org.dom4j:dom4j:2.1.3',
66-
'org.slf4j:slf4j-api:1.7.31'
67-
testImplementation 'junit:junit:4.12'
62+
implementation 'com.emc.ecs:smart-client:2.3.2'
63+
implementation('com.emc.ecs:object-transform:1.1.0') {
64+
exclude group: 'org.slf4j', module: 'slf4j-log4j12'
65+
}
66+
implementation 'commons-codec:commons-codec:1.15'
67+
implementation 'org.dom4j:dom4j:2.1.3'
68+
implementation 'org.slf4j:slf4j-api:1.7.32'
69+
testImplementation 'junit:junit:4.13.2'
70+
testRuntimeOnly 'org.slf4j:jcl-over-slf4j:1.7.32'
6871
testRuntimeOnly 'org.apache.logging.log4j:log4j-slf4j-impl:2.14.1'
6972
}
7073

src/main/java/com/emc/object/util/RestUtil.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -259,11 +259,10 @@ public static URI buildUri(String scheme, String host, int port, String path, St
259259
// workaround for https://bugs.openjdk.java.net/browse/JDK-8037396
260260
uriString = uriString.replace("[", "%5B").replace("]", "%5D");
261261

262-
// replace double-slash with /%2f (workaround for apache client)
263-
if (path != null && path.length() > 2 && path.charAt(0) == '/' && path.charAt(1) == '/') {
264-
int doubleSlashIndex = uriString.indexOf("//");
265-
if (scheme != null) doubleSlashIndex = uriString.indexOf("//", doubleSlashIndex + 2);
266-
uriString = uriString.substring(0, doubleSlashIndex) + "/%2F" + uriString.substring(doubleSlashIndex + 2);
262+
// replace double-slash with /%2f (otherwise apache client will normalize it to one slash)
263+
if (path.contains("//")) {
264+
if (scheme != null) uriString = uriString.substring(0, 8) + uriString.substring(8).replaceAll("//", "/%2F");
265+
else uriString = uriString.replaceAll("//", "/%2F");
267266
}
268267

269268
// Special case to handle "+" characters that URI doesn't handle well.
@@ -286,9 +285,9 @@ public static URI buildUri(String scheme, String host, int port, String path, St
286285
* this method works as if by invoking that method and then
287286
* <a href="#encode">encoding</a> the result. </p>
288287
*
289-
* @return The string form of this URI, encoded as needed
290-
* so that it only contains characters in the US-ASCII
291-
* charset
288+
* @return The string form of this URI, encoded as needed
289+
* so that it only contains characters in the US-ASCII
290+
* charset
292291
*/
293292
public static String toASCIIString(URI u) {
294293
String s = defineString(u);
@@ -354,7 +353,7 @@ private static String encode(String s) {
354353
return s;
355354

356355
// First check whether we actually need to encode
357-
for (int i = 0;;) {
356+
for (int i = 0; ; ) {
358357
if (s.charAt(i) >= '\u0080')
359358
break;
360359
if (++i >= n)
@@ -372,9 +371,9 @@ private static String encode(String s) {
372371
while (bb.hasRemaining()) {
373372
int b = bb.get() & 0xff;
374373
if (b >= 0x80)
375-
appendEscape(sb, (byte)b);
374+
appendEscape(sb, (byte) b);
376375
else
377-
sb.append((char)b);
376+
sb.append((char) b);
378377
}
379378
return sb.toString();
380379
}
@@ -398,6 +397,7 @@ public static URI replaceHost(URI uri, String host) throws URISyntaxException {
398397
public static URI replacePath(URI uri, String path) throws URISyntaxException {
399398
return buildUri(uri.getScheme(), uri.getHost(), uri.getPort(), path, uri.getRawQuery(), uri.getRawFragment());
400399
}
400+
401401
private static DateFormat getHeaderFormat() {
402402
DateFormat format = headerFormat.get();
403403
if (format == null) {
@@ -409,11 +409,11 @@ private static DateFormat getHeaderFormat() {
409409
}
410410

411411
public static String join(String separator, Iterable<String> items) {
412-
if(separator == null) throw new IllegalArgumentException("separator argument is null");
413-
if(items == null) throw new IllegalArgumentException("items argument is null");
412+
if (separator == null) throw new IllegalArgumentException("separator argument is null");
413+
if (items == null) throw new IllegalArgumentException("items argument is null");
414414
StringBuilder sb = new StringBuilder();
415-
for(String item : items) {
416-
if(sb.length() > 0) sb.append(separator);
415+
for (String item : items) {
416+
if (sb.length() > 0) sb.append(separator);
417417
sb.append(item);
418418
}
419419
return sb.toString();

src/test/java/com/emc/object/s3/S3EncryptionClientBasicTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ public void testRetries() throws Exception {
294294

295295
S3Config _config = createS3Config();
296296
_config.setFaultInjectionRate(0.4f);
297-
_config.setRetryLimit(6);
297+
_config.setRetryLimit(10);
298298
S3Client _client = new S3EncryptionClient(_config, createEncryptionConfig());
299299

300300
// make sure we hit at least one error

0 commit comments

Comments
 (0)