Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(links): embedded links with escaped chars [e.g. plus] (WPB-4402) #2268

Merged
merged 4 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}
Loading