Skip to content

Commit 3acbdfc

Browse files
authored
Part of the query is removed when URL is passed in Intent (#344)
* Reproduced failing test Signed-off-by: Arnau Mora Gras <[email protected]> * Fixed stripUrl Signed-off-by: Arnau Mora Gras <[email protected]> --------- Signed-off-by: Arnau Mora Gras <[email protected]>
1 parent dde075d commit 3acbdfc

File tree

3 files changed

+34
-19
lines changed

3 files changed

+34
-19
lines changed

app/src/main/java/at/bitfire/icsdroid/UriUtils.kt

+19
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,23 @@ object UriUtils {
3232

3333
return false
3434
}
35+
36+
/**
37+
* Strips the URL from a string. For example, the following string:
38+
* ```
39+
* "This is a URL: https://example.com"
40+
* ```
41+
* will return:
42+
* ```
43+
* "https://example.com"
44+
* ```
45+
* _Quotes are not included_
46+
* @return The URL found in the string
47+
* @throws IllegalArgumentException if no URL is found in the string
48+
*/
49+
fun String.stripUrl(): String? {
50+
return "([a-zA-Z]+)://(\\w+)(.\\w+)*[\\w.&?=*]*".toRegex()
51+
.find(this)
52+
?.value
53+
}
3554
}

app/src/main/java/at/bitfire/icsdroid/ui/views/AddCalendarActivity.kt

+1-19
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import androidx.compose.ui.platform.LocalContext
2121
import at.bitfire.icsdroid.Constants
2222
import at.bitfire.icsdroid.HttpClient
2323
import at.bitfire.icsdroid.R
24+
import at.bitfire.icsdroid.UriUtils.stripUrl
2425
import at.bitfire.icsdroid.calendar.LocalCalendar
2526
import at.bitfire.icsdroid.model.CreateSubscriptionModel
2627
import at.bitfire.icsdroid.model.CredentialsModel
@@ -148,23 +149,4 @@ class AddCalendarActivity : AppCompatActivity() {
148149
HttpClient.setForeground(true)
149150
}
150151

151-
/**
152-
* Strips the URL from a string. For example, the following string:
153-
* ```
154-
* "This is a URL: https://example.com"
155-
* ```
156-
* will return:
157-
* ```
158-
* "https://example.com"
159-
* ```
160-
* _Quotes are not included_
161-
* @return The URL found in the string
162-
* @throws IllegalArgumentException if no URL is found in the string
163-
*/
164-
private fun String.stripUrl(): String? {
165-
return "([a-zA-Z]+)://(\\w+)(.\\w+)*[/\\w*]*".toRegex()
166-
.find(this)
167-
?.value
168-
}
169-
170152
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package at.bitfire.icsdroid
2+
3+
import at.bitfire.icsdroid.UriUtils.stripUrl
4+
import org.junit.Assert.assertEquals
5+
import org.junit.Test
6+
7+
class UrlUtilsTest {
8+
@Test
9+
fun testStripUrl() {
10+
val url = "This is a URL: https://example.com/more/and/more?query=true.&par_am=test.more"
11+
val strippedUrl = url.stripUrl()
12+
assertEquals("https://example.com/more/and/more?query=true.&par_am=test.more", strippedUrl)
13+
}
14+
}

0 commit comments

Comments
 (0)