aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/facebook/FbUrlFormatter.kt1
-rw-r--r--app/src/test/kotlin/com/pitchedapps/frost/facebook/FbUrlTest.kt13
2 files changed, 11 insertions, 3 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbUrlFormatter.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbUrlFormatter.kt
index 4db75fff..22fc275f 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbUrlFormatter.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbUrlFormatter.kt
@@ -31,6 +31,7 @@ class FbUrlFormatter(url: String) {
var cleanedUrl = url
discardable.forEach { cleanedUrl = cleanedUrl.replace(it, "", true) }
converter.forEach { (k, v) -> cleanedUrl = cleanedUrl.replace(k, v, true) }
+ if (cleanedUrl != url) cleanedUrl = cleanedUrl.replaceFirst("&", "?")
cleanedUrl = URLDecoder.decode(cleanedUrl, StandardCharsets.UTF_8.name())
val qm = cleanedUrl.indexOf("?")
if (qm > -1) {
diff --git a/app/src/test/kotlin/com/pitchedapps/frost/facebook/FbUrlTest.kt b/app/src/test/kotlin/com/pitchedapps/frost/facebook/FbUrlTest.kt
index 57589b5e..5ac484b5 100644
--- a/app/src/test/kotlin/com/pitchedapps/frost/facebook/FbUrlTest.kt
+++ b/app/src/test/kotlin/com/pitchedapps/frost/facebook/FbUrlTest.kt
@@ -1,9 +1,6 @@
package com.pitchedapps.frost.facebook
-import okhttp3.HttpUrl
-import okio.Utf8
import org.junit.Test
-import java.net.URLDecoder
import kotlin.test.assertEquals
@@ -36,6 +33,16 @@ class FbUrlTest {
assertFbFormat("$prefix$suffix", "$prefix&ref=hello$suffix")
}
+ /**
+ * Unnecessary wraps should be removed & the query items should be bound properly (first & to ?)
+ */
+ @Test
+ fun queryConversion() {
+ val url = "https://m.facebook.com/l.php?u=https%3A%2F%2Fgoogle.ca&h=hi"
+ val expected = "https://google.ca?h=hi"
+ assertFbFormat(expected, url)
+ }
+
@Test
fun doubleDash() {
assertFbFormat("${FB_URL_BASE}relative", "$FB_URL_BASE/relative")