Skip to content

fixed double-slash normalization #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,15 @@ repositories {
}

dependencies {
implementation 'com.emc.ecs:smart-client:2.3.2',
'com.emc.ecs:object-transform:1.1.0',
'commons-codec:commons-codec:1.15',
'org.dom4j:dom4j:2.1.3',
'org.slf4j:slf4j-api:1.7.31'
testImplementation 'junit:junit:4.12'
implementation 'com.emc.ecs:smart-client:2.3.2'
implementation('com.emc.ecs:object-transform:1.1.0') {
exclude group: 'org.slf4j', module: 'slf4j-log4j12'
}
implementation 'commons-codec:commons-codec:1.15'
implementation 'org.dom4j:dom4j:2.1.3'
implementation 'org.slf4j:slf4j-api:1.7.32'
testImplementation 'junit:junit:4.13.2'
testRuntimeOnly 'org.slf4j:jcl-over-slf4j:1.7.32'
testRuntimeOnly 'org.apache.logging.log4j:log4j-slf4j-impl:2.14.1'
}

Expand Down
30 changes: 15 additions & 15 deletions src/main/java/com/emc/object/util/RestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,10 @@ public static URI buildUri(String scheme, String host, int port, String path, St
// workaround for https://bugs.openjdk.java.net/browse/JDK-8037396
uriString = uriString.replace("[", "%5B").replace("]", "%5D");

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible that path could be null by an unfriendly usage?
Will it work to process path before creating uri?

else uriString = uriString.replaceAll("//", "/%2F");
}

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

// First check whether we actually need to encode
for (int i = 0;;) {
for (int i = 0; ; ) {
if (s.charAt(i) >= '\u0080')
break;
if (++i >= n)
Expand All @@ -372,9 +371,9 @@ private static String encode(String s) {
while (bb.hasRemaining()) {
int b = bb.get() & 0xff;
if (b >= 0x80)
appendEscape(sb, (byte)b);
appendEscape(sb, (byte) b);
else
sb.append((char)b);
sb.append((char) b);
}
return sb.toString();
}
Expand All @@ -398,6 +397,7 @@ public static URI replaceHost(URI uri, String host) throws URISyntaxException {
public static URI replacePath(URI uri, String path) throws URISyntaxException {
return buildUri(uri.getScheme(), uri.getHost(), uri.getPort(), path, uri.getRawQuery(), uri.getRawFragment());
}

private static DateFormat getHeaderFormat() {
DateFormat format = headerFormat.get();
if (format == null) {
Expand All @@ -409,11 +409,11 @@ private static DateFormat getHeaderFormat() {
}

public static String join(String separator, Iterable<String> items) {
if(separator == null) throw new IllegalArgumentException("separator argument is null");
if(items == null) throw new IllegalArgumentException("items argument is null");
if (separator == null) throw new IllegalArgumentException("separator argument is null");
if (items == null) throw new IllegalArgumentException("items argument is null");
StringBuilder sb = new StringBuilder();
for(String item : items) {
if(sb.length() > 0) sb.append(separator);
for (String item : items) {
if (sb.length() > 0) sb.append(separator);
sb.append(item);
}
return sb.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ public void testRetries() throws Exception {

S3Config _config = createS3Config();
_config.setFaultInjectionRate(0.4f);
_config.setRetryLimit(6);
_config.setRetryLimit(10);
S3Client _client = new S3EncryptionClient(_config, createEncryptionConfig());

// make sure we hit at least one error
Expand Down