diff --git a/components/support/utils/src/main/java/mozilla/components/support/utils/URLStringUtils.kt b/components/support/utils/src/main/java/mozilla/components/support/utils/URLStringUtils.kt index 6500985be44..e2f7e5e63c6 100644 --- a/components/support/utils/src/main/java/mozilla/components/support/utils/URLStringUtils.kt +++ b/components/support/utils/src/main/java/mozilla/components/support/utils/URLStringUtils.kt @@ -97,6 +97,7 @@ object URLStringUtils { * https/http and/or WWW prefixes and/or trailing slash when applicable. */ fun toDisplayUrl(originalUrl: CharSequence) = + "\u200E" + // use the left-to-right mark to always enforce LTR for displayed URLs maybeStripTrailingSlash(maybeStripUrlProtocol(originalUrl)) private fun maybeStripUrlProtocol(url: CharSequence): CharSequence { diff --git a/components/support/utils/src/test/java/mozilla/components/support/utils/URLStringUtilsTest.kt b/components/support/utils/src/test/java/mozilla/components/support/utils/URLStringUtilsTest.kt index a1d119b1c48..2186e02ca7f 100644 --- a/components/support/utils/src/test/java/mozilla/components/support/utils/URLStringUtilsTest.kt +++ b/components/support/utils/src/test/java/mozilla/components/support/utils/URLStringUtilsTest.kt @@ -130,42 +130,48 @@ class URLStringUtilsTest { @Test fun stripUrlSchemeUrlWithHttps() { val testDisplayUrl = URLStringUtils.toDisplayUrl("https://mozilla.com") - assertEquals("mozilla.com", testDisplayUrl) + assertEquals("\u200Emozilla.com", testDisplayUrl) } @Test fun stripTrailingSlash() { val testDisplayUrl = URLStringUtils.toDisplayUrl("mozilla.com/") - assertEquals("mozilla.com", testDisplayUrl) + assertEquals("\u200Emozilla.com", testDisplayUrl) } @Test fun stripUrlSchemeUrlWithHttpsAndTrailingSlash() { val testDisplayUrl = URLStringUtils.toDisplayUrl("https://mozilla.com/") - assertEquals("mozilla.com", testDisplayUrl) + assertEquals("\u200Emozilla.com", testDisplayUrl) } @Test fun stripUrlSchemeUrlWithHttp() { val testDisplayUrl = URLStringUtils.toDisplayUrl("http://mozilla.com") - assertEquals("mozilla.com", testDisplayUrl) + assertEquals("\u200Emozilla.com", testDisplayUrl) } @Test fun stripUrlSubdomainUrlWithHttps() { val testDisplayUrl = URLStringUtils.toDisplayUrl("https://www.mozilla.com") - assertEquals("mozilla.com", testDisplayUrl) + assertEquals("\u200Emozilla.com", testDisplayUrl) } @Test fun stripUrlSubdomainUrlWithHttp() { val testDisplayUrl = URLStringUtils.toDisplayUrl("http://www.mozilla.com") - assertEquals("mozilla.com", testDisplayUrl) + assertEquals("\u200Emozilla.com", testDisplayUrl) } @Test fun stripUrlSchemeAndSubdomainUrlNoMatch() { val testDisplayUrl = URLStringUtils.toDisplayUrl("zzz://www.mozillahttp://.com") - assertEquals("zzz://www.mozillahttp://.com", testDisplayUrl) + assertEquals("\u200Ezzz://www.mozillahttp://.com", testDisplayUrl) + } + + @Test + fun alwaysShowDisplayUrlAsLTR() { + val testDisplayUrl = URLStringUtils.toDisplayUrl("http://ختار.ار/www.mozilla.org/1") + assertEquals("\u200Eختار.ار/www.mozilla.org/1", testDisplayUrl) } }