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

Commit 484b4be8 authored by zhibinliu's avatar zhibinliu Committed by Android Build Coastguard Worker
Browse files

Check package name format before using it for SPA nav

Bug: b/372895305
Test: unit test
Flag: EXEMPT bug fix
(cherry picked from commit b2ee5ccf)
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:9e4964ff220a40282478fd3769e20779ce49a342)
Merged-In: Ife615c78c48a2d6f5b938c880c9c2128c5551644
Change-Id: Ife615c78c48a2d6f5b938c880c9c2128c5551644
parent f16fa584
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -38,7 +38,7 @@ class SpaAppBridgeActivity : Activity() {

    companion object {
        fun getDestinationForApp(destinationPrefix: String, intent: Intent): String? {
            val packageName = intent.data?.schemeSpecificPart ?: return null
            val packageName = intent.data?.schemeSpecificPart?.takeIf { Regex("^([a-zA-Z]\\w*\\.)*[a-zA-Z]\\w*$").matches(it) } ?: return null
            return "$destinationPrefix/$packageName/${UserHandle.myUserId()}"
        }
    }
+10 −0
Original line number Diff line number Diff line
@@ -37,6 +37,16 @@ class SpaAppBridgeActivityTest {

        assertThat(destination).isEqualTo("$DESTINATION/$PACKAGE_NAME/${UserHandle.myUserId()}")
    }
    @Test
    fun getDestinationForApp_hasMalformedPackageName() {
        val intent = Intent().apply {
            data = Uri.parse("package:package.name/10#")
        }

        val destination = getDestinationForApp(DESTINATION, intent)

        assertThat(destination).isNull()
    }

    @Test
    fun getDestinationForApp_noPackageName() {