Skip to content

Commit

Permalink
Fix appendRelativePath
Browse files Browse the repository at this point in the history
  • Loading branch information
kiyeonk committed Dec 4, 2023
1 parent f8e6807 commit a6613be
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ internal fun URLBuilder.appendRelativePath(relativePath: String): URLBuilder {
}

".." -> {
// Clean up last path if exist
if (index == 0 && !isLastSlash) {
segments.removeLastOrNull()
}
if (segments.isNotEmpty()) {
segments.removeLast()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ class StringUtilTest {
assertEquals("https://example2.com/one", StringUtil.resolve("http://example.com/", "https://example2.com/one"))
assertEquals("https://example.com/one", StringUtil.resolve("wrong", "https://example.com/one"))
assertEquals("https://example.com/one", StringUtil.resolve("https://example.com/one", ""))
assertEquals("https://example.com/one/two.c", StringUtil.resolve("https://example.com/one/two/", "../two.c"))
assertEquals("https://example.com/two.c", StringUtil.resolve("https://example.com/one/two", "../two.c"))
assertEquals("", StringUtil.resolve("wrong", "also wrong"))
assertEquals("ftp://example.com/one", StringUtil.resolve("ftp://example.com/two/", "../one"))
assertEquals("ftp://example.com/one/two.c", StringUtil.resolve("ftp://example.com/one/", "./two.c"))
Expand Down

0 comments on commit a6613be

Please sign in to comment.