Skip to content

Commit

Permalink
For mozilla-mobile#10598 - Always display URLs left to right
Browse files Browse the repository at this point in the history
  • Loading branch information
Mugurell authored and Grisha Kruglov committed Sep 11, 2021
1 parent 819972c commit aa28d7a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit aa28d7a

Please sign in to comment.