Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
For #10598 - Always display URLs left to right
Browse files Browse the repository at this point in the history
  • Loading branch information
Mugurell authored and mergify[bot] committed Jul 16, 2021
1 parent 5f4c749 commit faecf0f
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)
}
}

1 comment on commit faecf0f

@firefoxci-taskcluster
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh oh! Looks like an error! Details

Failed to fetch task artifact public/github/customCheckRunText.md for GitHub integration.
Make sure the artifact exists on the worker or other location.

Please sign in to comment.