Commit 7b8928df authored by davigonz's avatar davigonz

Fix UrlUtils method to properly compare urls containing special characters

parent 61712ec2
Pipeline #59411128 failed with stage
in 46 seconds
......@@ -25,6 +25,6 @@ Email: [play@bitfire.at](mailto:play@bitfire.at) (please use the forum instead)
## Contributors
* Ricki Hirner (initial contributor)
* David González Verdugo (dgonzalez@owncloud.com)
* David González Verdugo (https://github.com/davigonz)
* Matt Jacobsen (https://gitlab.com/mattjacobsen)
......@@ -14,8 +14,8 @@ object UrlUtils {
fun equals(url1: HttpUrl, url2: HttpUrl): Boolean {
// if okhttp thinks the two URLs are equal, they're in any case
// (and it's a simple String comparison)
if (url1 == url2)
// (and it's a simple String comparison, ignoring case)
if (url1.toString().equals(url2.toString(), true))
return true
val uri1 = url1.uri()
......@@ -64,5 +64,4 @@ object UrlUtils {
else
url.newBuilder().addPathSegment("").build()
}
}
......@@ -21,6 +21,8 @@ class UrlUtilsTest {
assertFalse(UrlUtils.equals(HttpUrl.parse("http://host/resource")!!, HttpUrl.parse("http://host/resource/")!!))
assertFalse(UrlUtils.equals(HttpUrl.parse("http://host/resource")!!, HttpUrl.parse("http://host:81/resource")!!))
assertTrue(UrlUtils.equals(HttpUrl.parse("http://host/%5bresource%5d/")!!, HttpUrl.parse("http://host/%5Bresource%5D/")!!))
}
@Test
......@@ -50,5 +52,4 @@ class UrlUtilsTest {
assertEquals(HttpUrl.parse("http://host/resource/")!!, UrlUtils.withTrailingSlash(HttpUrl.parse("http://host/resource")!!))
assertEquals(HttpUrl.parse("http://host/resource/")!!, UrlUtils.withTrailingSlash(HttpUrl.parse("http://host/resource/")!!))
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment