Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 3acbdfc1 authored by Arnau Mora's avatar Arnau Mora Committed by GitHub
Browse files

Part of the query is removed when URL is passed in Intent (#344)



* Reproduced failing test

Signed-off-by: default avatarArnau Mora Gras <arnyminerz@proton.me>

* Fixed stripUrl

Signed-off-by: default avatarArnau Mora Gras <arnyminerz@proton.me>

---------

Signed-off-by: default avatarArnau Mora Gras <arnyminerz@proton.me>
parent dde075d8
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -32,4 +32,23 @@ object UriUtils {

        return false
    }

    /**
     * Strips the URL from a string. For example, the following string:
     * ```
     * "This is a URL: https://example.com"
     * ```
     * will return:
     * ```
     * "https://example.com"
     * ```
     * _Quotes are not included_
     * @return The URL found in the string
     * @throws IllegalArgumentException if no URL is found in the string
     */
    fun String.stripUrl(): String? {
        return "([a-zA-Z]+)://(\\w+)(.\\w+)*[\\w.&?=*]*".toRegex()
            .find(this)
            ?.value
    }
}
 No newline at end of file
+1 −19
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import androidx.compose.ui.platform.LocalContext
import at.bitfire.icsdroid.Constants
import at.bitfire.icsdroid.HttpClient
import at.bitfire.icsdroid.R
import at.bitfire.icsdroid.UriUtils.stripUrl
import at.bitfire.icsdroid.calendar.LocalCalendar
import at.bitfire.icsdroid.model.CreateSubscriptionModel
import at.bitfire.icsdroid.model.CredentialsModel
@@ -148,23 +149,4 @@ class AddCalendarActivity : AppCompatActivity() {
        HttpClient.setForeground(true)
    }

    /**
     * Strips the URL from a string. For example, the following string:
     * ```
     * "This is a URL: https://example.com"
     * ```
     * will return:
     * ```
     * "https://example.com"
     * ```
     * _Quotes are not included_
     * @return The URL found in the string
     * @throws IllegalArgumentException if no URL is found in the string
     */
    private fun String.stripUrl(): String? {
        return "([a-zA-Z]+)://(\\w+)(.\\w+)*[/\\w*]*".toRegex()
            .find(this)
            ?.value
    }

}
+14 −0
Original line number Diff line number Diff line
package at.bitfire.icsdroid

import at.bitfire.icsdroid.UriUtils.stripUrl
import org.junit.Assert.assertEquals
import org.junit.Test

class UrlUtilsTest {
    @Test
    fun testStripUrl() {
        val url = "This is a URL: https://example.com/more/and/more?query=true.&par_am=test.more"
        val strippedUrl = url.stripUrl()
        assertEquals("https://example.com/more/and/more?query=true.&par_am=test.more", strippedUrl)
    }
}