8272702: Resolving URI relative path with no / may lead to incorrect toString

Reviewed-by: dfuchs, michaelm
This commit is contained in:
KIRIYAMA Takuya 2022-08-22 09:22:59 +00:00 committed by Daniel Fuchs
parent 7b5f9edb59
commit 79597f1ea6
2 changed files with 32 additions and 9 deletions

View file

@ -2106,7 +2106,7 @@ public final class URI
// -- Normalization, resolution, and relativization --
// RFC2396 5.2 (6)
private static String resolvePath(String base, String child)
private static String resolvePath(String base, String child, boolean absolute)
{
int i = base.lastIndexOf('/');
int cn = child.length();
@ -2117,12 +2117,13 @@ public final class URI
if (i >= 0)
path = base.substring(0, i + 1);
} else {
// 5.2 (6a)
if (i >= 0)
// 5.2 (6a-b)
if (i >= 0 || !absolute) {
path = base.substring(0, i + 1).concat(child);
// 5.2 (6b)
else
path = child;
} else {
path = "/".concat(child);
}
}
// 5.2 (6c-f)
@ -2183,7 +2184,7 @@ public final class URI
ru.path = child.path;
} else {
// 5.2 (6): Resolve relative path
ru.path = resolvePath(base.path, cp);
ru.path = resolvePath(base.path, cp, base.isAbsolute());
}
} else {
ru.authority = child.authority;