Skip to content

Commit

Permalink
Double-slash URI issue helidon-io#7474
Browse files Browse the repository at this point in the history
  • Loading branch information
danielkec committed Sep 24, 2023
1 parent 85f5202 commit 863a7f7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public String toString() {
@Override
public void validate() {
if (decodedPath == null) {
this.decodedPath = URI.create(rawPath).normalize().getPath();
this.decodedPath = decode(rawPath);
}
}

Expand All @@ -125,6 +125,11 @@ private static String decode(String rawPath) {
return rawPath;
}

if (doubleSlash == 0) {
// URI.create("//foo/bar").normalize().getPath() --> "/bar"
rawPath = rawPath.substring(1);
}

return URI.create(rawPath).normalize().getPath();
}
}
14 changes: 14 additions & 0 deletions common/uri/src/test/java/io/helidon/common/uri/UriPathTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package io.helidon.common.uri;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
Expand All @@ -37,4 +39,16 @@ void testEncodeSpace() {
assertThat(path.path(), is("/my path"));
assertThat(path.rawPath(), is("/my%20path"));
}

@ParameterizedTest
@ValueSource(strings = {
"//foo/bar",
"//foo//bar",
"/foo//bar",
"/foo/bar",
})
void testDoubleSlash(String rawPath) {
UriPath path = UriPath.create(rawPath);
assertThat(path.path(), is("/foo/bar"));
}
}

0 comments on commit 863a7f7

Please sign in to comment.