diff --git a/components/browser/icons/src/main/java/mozilla/components/browser/icons/extension/IconMessage.kt b/components/browser/icons/src/main/java/mozilla/components/browser/icons/extension/IconMessage.kt index ac7d8d2452c..7571ad60c0a 100644 --- a/components/browser/icons/src/main/java/mozilla/components/browser/icons/extension/IconMessage.kt +++ b/components/browser/icons/src/main/java/mozilla/components/browser/icons/extension/IconMessage.kt @@ -88,7 +88,7 @@ private fun JSONObject.toIconResource(): IconRequest.Resource? { val maskable = optBoolean("maskable", false) return IconRequest.Resource( - url = url, + url = url.trim(), type = type, sizes = sizes, mimeType = if (mimeType.isNullOrEmpty()) null else mimeType, diff --git a/components/browser/icons/src/test/java/mozilla/components/browser/icons/extension/IconMessageKtTest.kt b/components/browser/icons/src/test/java/mozilla/components/browser/icons/extension/IconMessageKtTest.kt index df134df789b..1de33b5a727 100644 --- a/components/browser/icons/src/test/java/mozilla/components/browser/icons/extension/IconMessageKtTest.kt +++ b/components/browser/icons/src/test/java/mozilla/components/browser/icons/extension/IconMessageKtTest.kt @@ -42,4 +42,21 @@ class IconMessageKtTest { val restoredResources = json.toIconResources() assertEquals(resources, restoredResources) } + + @Test + fun `Url must be sanitized`() { + val resources = listOf( + IconRequest.Resource( + url = "\nhttps://www.mozilla.org/icon64.png\n", + sizes = listOf(Size(64, 64)), + mimeType = "image/png", + type = IconRequest.Resource.Type.FAVICON + ) + ) + + val json = resources.toJSON() + + val restoredResource = json.toIconResources().first() + assertEquals("https://www.mozilla.org/icon64.png", restoredResource.url) + } } diff --git a/docs/changelog.md b/docs/changelog.md index 66e6539964a..bfbcd397076 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -12,6 +12,9 @@ permalink: /changelog/ * [Gecko](https://github.com/mozilla-mobile/android-components/blob/master/buildSrc/src/main/java/Gecko.kt) * [Configuration](https://github.com/mozilla-mobile/android-components/blob/master/buildSrc/src/main/java/Config.kt) +* **browser-icons** + * Fixed issue [#7142](https://github.com/mozilla-mobile/android-components/issues/7142) + # 44.0.0 * [Commits](https://github.com/mozilla-mobile/android-components/compare/v43.0.0...v44.0.0)