Skip to content

Commit

Permalink
Merge pull request #10 from kiyeonk/fix-resolve-relative-urls
Browse files Browse the repository at this point in the history
Fix`URLBuilder.appendRelativePath` to work correctly
  • Loading branch information
itboy87 authored Dec 8, 2023
2 parents 1e78200 + a6613be commit 4afd7d2
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 4afd7d2

Please sign in to comment.