Skip to content

Commit 96963bd

Browse files
committed
Keep trailing slashes
1 parent 0e8bbab commit 96963bd

File tree

2 files changed

+15
-1
lines changed
  • readium/shared/src
    • main/java/org/readium/r2/shared/util
    • test/java/org/readium/r2/shared/util

2 files changed

+15
-1
lines changed

readium/shared/src/main/java/org/readium/r2/shared/util/Url.kt

+5-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,11 @@ public sealed class Url : Parcelable {
182182
uri.buildUpon()
183183
.apply {
184184
path?.let {
185-
path(File(it).normalize().path)
185+
var normalizedPath = File(it).normalize().path
186+
if (it.endsWith("/")) {
187+
normalizedPath += "/"
188+
}
189+
path(normalizedPath)
186190
}
187191

188192
if (this@Url is AbsoluteUrl) {

readium/shared/src/test/java/org/readium/r2/shared/util/UrlTest.kt

+10
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,16 @@ class UrlTest {
432432
Url("foo/./bar/../../../baz")!!.normalize().toString()
433433
)
434434

435+
// Trailing slash is kept.
436+
assertEquals(
437+
"http://example.com/foo/",
438+
Url("http://example.com/foo/")!!.normalize().toString()
439+
)
440+
assertEquals(
441+
"foo/",
442+
Url("foo/")!!.normalize().toString()
443+
)
444+
435445
// The other components are left as-is.
436446
assertEquals(
437447
"http://user:password@example.com:443/foo?b=b&a=a#fragment",

0 commit comments

Comments
 (0)