Skip to content

Commit

Permalink
fix(links): embedded links with escaped chars [e.g. plus] (WPB-4402) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mchenani committed Oct 18, 2023
1 parent 858d976 commit e3dddf1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
9 changes: 3 additions & 6 deletions app/src/main/kotlin/com/wire/android/util/UriUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package com.wire.android.util

import java.net.URI
import java.net.URLDecoder

fun containsSchema(url: String): Boolean {
return try {
Expand All @@ -29,11 +28,9 @@ fun containsSchema(url: String): Boolean {
}

fun normalizeLink(url: String): String {
val normalizedUrl = URLDecoder.decode(url, "UTF-8") // Decode URL to human-readable format

return if (containsSchema(normalizedUrl)) {
normalizedUrl
return if (containsSchema(url)) {
url
} else {
"https://$normalizedUrl"
"https://$url"
}
}
7 changes: 7 additions & 0 deletions app/src/test/kotlin/com/wire/android/util/UriUtilTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,11 @@ class UriUtilTest {
val actual = normalizeLink(input)
assertEquals(expected, actual)
}

@Test
fun givenEncodedLink_whenTheLinkIsValidWithSchema_thenReturnsTheSameLink() {
val input = "https://google.com/this+is+a+link+with+space"
val actual = normalizeLink(input)
assertEquals(input, actual)
}
}

0 comments on commit e3dddf1

Please sign in to comment.