commit 9fcffbea18de868276fc53a5ee4bbc5cf23d3799
parent 931064cb72b2f552fcd69d7c4fb1deb946928107
Author: Harrison Oglesby <oglesby.harrison@gmail.com>
Date: Mon, 17 Nov 2025 22:38:29 +0000
Bug 1998355 - Fix missing format strings for settings search results r=android-reviewers,petru
Differential Revision: https://phabricator.services.mozilla.com/D272364
Diffstat:
2 files changed, 60 insertions(+), 3 deletions(-)
diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/settings/settingssearch/DefaultFenixSettingsIndexer.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/settings/settingssearch/DefaultFenixSettingsIndexer.kt
@@ -10,6 +10,7 @@ import android.content.res.Resources
import android.content.res.XmlResourceParser
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
+import org.mozilla.fenix.R
import java.io.IOException
/**
@@ -262,10 +263,15 @@ class DefaultFenixSettingsIndexer(private val context: Context) : SettingsIndexe
val resourceId = context.resources.getIdentifier(
resourceName, "string", context.packageName,
)
- if (resourceId != 0) {
- context.getString(resourceId)
+ if (resourceId == 0) {
+ return ""
+ }
+
+ if (stringsWithRequiredFormatting.contains(resourceId)) {
+ val appName = context.getString(R.string.app_name)
+ context.getString(resourceId, appName)
} else {
- ""
+ context.getString(resourceId)
}
} catch (e: Resources.NotFoundException) {
""
@@ -312,5 +318,16 @@ class DefaultFenixSettingsIndexer(private val context: Context) : SettingsIndexe
PreferenceFileInformation.TrackingProtectionPreferences,
PreferenceFileInformation.SaveLoginsPreferences,
)
+
+ /**
+ * List of strings that require format args.
+ *
+ * All of them require the app name.
+ */
+ val stringsWithRequiredFormatting = listOf(
+ R.string.preferences_downloads_settings_clean_up_files_title,
+ R.string.preferences_show_nonsponsored_suggestions,
+ R.string.preferences_about,
+ )
}
}
diff --git a/mobile/android/fenix/app/src/test/java/org/mozilla/fenix/settings/settingssearch/DefaultFenixSettingsIndexerTest.kt b/mobile/android/fenix/app/src/test/java/org/mozilla/fenix/settings/settingssearch/DefaultFenixSettingsIndexerTest.kt
@@ -0,0 +1,40 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+package org.mozilla.fenix.settings.settingssearch
+
+import androidx.test.core.app.ApplicationProvider
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import kotlinx.coroutines.runBlocking
+import org.junit.Assert.assertTrue
+import org.junit.Before
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.robolectric.annotation.Config
+
+@RunWith(AndroidJUnit4::class)
+@Config(manifest = Config.NONE)
+class DefaultFenixSettingsIndexerTest {
+
+ private lateinit var indexer: DefaultFenixSettingsIndexer
+
+ @Before
+ fun setUp() {
+ indexer = DefaultFenixSettingsIndexer(ApplicationProvider.getApplicationContext())
+ indexer.indexAllSettings()
+ }
+
+ /**
+ * Test that a query containing special characters like '%' does not crash
+ * and correctly returns an empty list if no matches are found.
+ */
+ @Test
+ fun `GIVEN a query with special characters with getSettingsWithQuery THEN return empty list`() = runBlocking {
+ val query = "%"
+
+ val results = indexer.getSettingsWithQuery(query)
+
+ assertTrue(results.isEmpty())
+ }
+}