From a4bc4e78ed71f207d454817922f2413763535ad3 Mon Sep 17 00:00:00 2001 From: Paul Marks Date: Sat, 14 Oct 2023 13:41:12 -0400 Subject: [PATCH 1/9] Bug 1803465 - extend isURLLenient to match IPv6 literals Also known as Bug 1807752 --- .../support/ktx/util/URLStringUtils.kt | 20 +++++++++---------- .../support/utils/URLStringUtilsTest.kt | 12 +++++++++++ 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/android-components/components/support/utils/src/main/java/mozilla/components/support/ktx/util/URLStringUtils.kt b/android-components/components/support/utils/src/main/java/mozilla/components/support/ktx/util/URLStringUtils.kt index 755b99e8cf5e..e199f825e02e 100644 --- a/android-components/components/support/utils/src/main/java/mozilla/components/support/ktx/util/URLStringUtils.kt +++ b/android-components/components/support/utils/src/main/java/mozilla/components/support/ktx/util/URLStringUtils.kt @@ -44,20 +44,20 @@ object URLStringUtils { private val isURLLenient by lazy { // Be lenient about what is classified as potentially a URL. - // (\w+-+)*\w+(://[/]*|:|\.)(\w+-+)*\w+([\S&&[^\w-]]\S*)? - // ------- ------- + // (\w+-+)*[\w\[]+(://[/]*|:|\.)(\w+-+)*[\w\[:]+([\S&&[^\w-]]\S*)? + // -------- -------- // 0 or more pairs of consecutive word letters or dashes - // --- --- - // followed by at least a single word letter. - // ----------- ---------- + // ------- -------- + // followed by at least a single word letter or [ipv6::] character. + // --------------- ---------------- // Combined, that means "w", "w-w", "w-w-w", etc match, but "w-", "w-w-", "w-w-w-" do not. - // -------------- + // -------------- // That surrounds :, :// or . - // - + // - // At the end, there may be an optional - // ------------ + // ------------ // non-word, non-- but still non-space character (e.g., ':', '/', '.', '?' but not 'a', '-', '\t') - // --- + // --- // and 0 or more non-space characters. // // These are some (odd) examples of valid urls according to this pattern: @@ -77,7 +77,7 @@ object URLStringUtils { // www.c-c- // 3-3 Pattern.compile( - "^\\s*(\\w+-+)*\\w+(://[/]*|:|\\.)(\\w+-+)*\\w+([\\S&&[^\\w-]]\\S*)?\\s*$", + "^\\s*(\\w+-+)*[\\w\\[]+(://[/]*|:|\\.)(\\w+-+)*[\\w\\[:]+([\\S&&[^\\w-]]\\S*)?\\s*$", flags, ) } diff --git a/android-components/components/support/utils/src/test/java/mozilla/components/support/utils/URLStringUtilsTest.kt b/android-components/components/support/utils/src/test/java/mozilla/components/support/utils/URLStringUtilsTest.kt index 6c9ca12739eb..95afdd6d90e9 100644 --- a/android-components/components/support/utils/src/test/java/mozilla/components/support/utils/URLStringUtilsTest.kt +++ b/android-components/components/support/utils/src/test/java/mozilla/components/support/utils/URLStringUtilsTest.kt @@ -88,6 +88,18 @@ class URLStringUtilsTest { assertFalse(isURLLike("www.c-c- ")) assertFalse(isURLLike("3-3 ")) + // IPv6 literals + assertTrue(isURLLike("[::]")) + assertTrue(isURLLike("[::1]")) + assertTrue(isURLLike("[1::]")) + assertTrue(isURLLike("[::]/")) + assertTrue(isURLLike("https:[::]")) + assertTrue(isURLLike("https://[::]")) + assertTrue(isURLLike("https://[::1]")) + assertTrue(isURLLike("https://[1::]")) + assertTrue(isURLLike("https://[2001:db8::1.2.3.4]/")) + assertTrue(isURLLike("[2001:db8::1.2.3.4]/")) + // Examples from issues assertTrue(isURLLike("https://abc--cba.com/")) // #7096 } From 6ab5019802471e971cf7c7a391ad3da68516383c Mon Sep 17 00:00:00 2001 From: Paul Marks Date: Sat, 14 Oct 2023 15:08:40 -0400 Subject: [PATCH 2/9] Bug 1803465 - Keep autolinkWebUrlPattern in sync with isURLLenient. This lets the "Fill link from clipboard" feature accept IPv6 literals like https://[2606:4700:4700::1111] --- .../java/mozilla/components/support/utils/WebURLFinder.kt | 3 ++- .../mozilla/components/support/utils/WebURLFinderTest.kt | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/android-components/components/support/utils/src/main/java/mozilla/components/support/utils/WebURLFinder.kt b/android-components/components/support/utils/src/main/java/mozilla/components/support/utils/WebURLFinder.kt index a2a3b9e7e43e..8f3c4df09849 100644 --- a/android-components/components/support/utils/src/main/java/mozilla/components/support/utils/WebURLFinder.kt +++ b/android-components/components/support/utils/src/main/java/mozilla/components/support/utils/WebURLFinder.kt @@ -75,7 +75,8 @@ class WebURLFinder { companion object { // Taken from mozilla.components.support.ktx.util.URLStringUtils. See documentation // there for a complete description. - private const val autolinkWebUrlPattern = "(\\w+-)*\\w+(://[/]*|:|\\.)(\\w+-)*\\w+([\\S&&[^\\w-]]\\S*)?" + private const val autolinkWebUrlPattern = + "(\\w+-+)*[\\w\\[]+(://[/]*|:|\\.)(\\w+-+)*[\\w\\[:]+([\\S&&[^\\w-]]\\S*)?" private val autolinkWebUrl by lazy { Pattern.compile(autolinkWebUrlPattern, 0) diff --git a/android-components/components/support/utils/src/test/java/mozilla/components/support/utils/WebURLFinderTest.kt b/android-components/components/support/utils/src/test/java/mozilla/components/support/utils/WebURLFinderTest.kt index 6afe8aa92c44..d523e711d5fa 100644 --- a/android-components/components/support/utils/src/test/java/mozilla/components/support/utils/WebURLFinderTest.kt +++ b/android-components/components/support/utils/src/test/java/mozilla/components/support/utils/WebURLFinderTest.kt @@ -59,6 +59,11 @@ class WebURLFinderTest { ) assertEquals("http://ß.de/", find("http://ß.de/ çnn.çơḿ")) assertEquals("htt-p://ß.de/", find("çnn.çơḿ htt-p://ß.de/")) + assertEquals( + "http://[2001:db8::1.2.3.4]:8080/inner#anchor&arg=1", + find("test.com http://[2001:db8::1.2.3.4]:8080/inner#anchor&arg=1"), + ) + assertEquals("http://[::]", find("test.com http://[::]")) } @Test @@ -68,6 +73,9 @@ class WebURLFinderTest { assertEquals("n-oscheme.com", find("n-oscheme.com example.com")) assertEquals("n-oscheme.com", find("----------n-oscheme.com ")) assertEquals("n-oscheme.ç", find("----------n-oscheme.ç-----------------------")) + + // We would ideally test "[::] example.com" here, but java.net.URI + // doesn't seem to accept IPv6 literals without a scheme. } @Test From 5202c23f355ef85cffd5da3b1f91c412d8530c99 Mon Sep 17 00:00:00 2001 From: Paul Marks Date: Thu, 19 Oct 2023 14:36:40 -0400 Subject: [PATCH 3/9] Bug 1803465 - more IPv6 test cases for isURLLenient --- .../support/utils/URLStringUtilsTest.kt | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/android-components/components/support/utils/src/test/java/mozilla/components/support/utils/URLStringUtilsTest.kt b/android-components/components/support/utils/src/test/java/mozilla/components/support/utils/URLStringUtilsTest.kt index 95afdd6d90e9..069f21b5b4fe 100644 --- a/android-components/components/support/utils/src/test/java/mozilla/components/support/utils/URLStringUtilsTest.kt +++ b/android-components/components/support/utils/src/test/java/mozilla/components/support/utils/URLStringUtilsTest.kt @@ -93,13 +93,35 @@ class URLStringUtilsTest { assertTrue(isURLLike("[::1]")) assertTrue(isURLLike("[1::]")) assertTrue(isURLLike("[::]/")) + assertTrue(isURLLike("[1:2:3:4:5:6:7:8]")) assertTrue(isURLLike("https:[::]")) assertTrue(isURLLike("https://[::]")) assertTrue(isURLLike("https://[::1]")) assertTrue(isURLLike("https://[1::]")) assertTrue(isURLLike("https://[2001:db8::1.2.3.4]/")) + assertTrue(isURLLike("https://[1:2:3:4:5:6:7:8]/")) assertTrue(isURLLike("[2001:db8::1.2.3.4]/")) + // Invalid IPv6 literals, just to illustrate the limits of the regex. + assertFalse(isURLLike("::1")) + assertFalse(isURLLike(":::")) + assertFalse(isURLLike("[[http://]]")) + assertFalse(isURLLike("[[[")) + assertFalse(isURLLike("[[[:")) + assertFalse(isURLLike("[[[:/")) + assertFalse(isURLLike("http://]]]")) + assertTrue(isURLLike("[:::")) + assertTrue(isURLLike("fe80::")) + assertTrue(isURLLike("x:[")) + assertTrue(isURLLike("http://[::")) + assertTrue(isURLLike("http://[::/path")) + assertTrue(isURLLike("http://[::?query")) + assertTrue(isURLLike("[[http://banana]]")) + assertTrue(isURLLike("http://[[[")) + assertTrue(isURLLike("[[[::")) + assertTrue(isURLLike("[[[::/")) + assertTrue(isURLLike("http://[1.2.3]")) + // Examples from issues assertTrue(isURLLike("https://abc--cba.com/")) // #7096 } From 1cd491af9f1e30b9f914ccd196e1e8c703b1bf16 Mon Sep 17 00:00:00 2001 From: Paul Marks Date: Thu, 19 Oct 2023 15:22:22 -0400 Subject: [PATCH 4/9] Bug 1803465 - Update changelog.md --- docs/changelog.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/changelog.md b/docs/changelog.md index 2e6254eead2b..4e88415b7f95 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -27,6 +27,9 @@ permalink: /changelog/ * `SessionState.isProductUrl` is not affected for private tabs as shopping mode is disabled in private tabs. [Bug 1847063](https://bugzilla.mozilla.org/show_bug.cgi?id=1847063) * `SessionState.isProductUrl` has been moved to `ContentState.isProductUrl`. [Bug 1857287](https://bugzilla.mozilla.org/show_bug.cgi?id=1857287) +* **support-utils** + * Recognize IPv6 literals in the address bar. [Bug 1803465](https://bugzilla.mozilla.org/show_bug.cgi?id=1803465) + # 119.0 * [Commits](https://github.com/mozilla-mobile/firefox-android/compare/releases_v118..releases_v119) * [Dependencies](https://github.com/mozilla-mobile/firefox-android/blob/releases_v119/android-components/plugins/dependencies/src/main/java/DependenciesPlugin.kt) From 9760f8494f4458ee28c2a12b01c2f73de141e84a Mon Sep 17 00:00:00 2001 From: Paul Marks Date: Tue, 24 Oct 2023 12:54:37 -0400 Subject: [PATCH 5/9] Bug 1803465 - Bump IPv6 literals to Firefox 121 --- docs/changelog.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/changelog.md b/docs/changelog.md index 4e88415b7f95..67e10329d640 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -10,6 +10,9 @@ permalink: /changelog/ * [Gecko](https://github.com/mozilla-mobile/firefox-android/blob/main/android-components/plugins/dependencies/src/main/java/Gecko.kt) * [Configuration](https://github.com/mozilla-mobile/firefox-android/blob/main/android-components/.config.yml) +* **support-utils** + * Recognize IPv6 literals in the address bar. [Bug 1803465](https://bugzilla.mozilla.org/show_bug.cgi?id=1803465) + # 120.0 * [Commits](https://github.com/mozilla-mobile/firefox-android/compare/releases_v119..releases_v120) * [Dependencies](https://github.com/mozilla-mobile/firefox-android/blob/releases_v120/android-components/plugins/dependencies/src/main/java/DependenciesPlugin.kt) @@ -27,9 +30,6 @@ permalink: /changelog/ * `SessionState.isProductUrl` is not affected for private tabs as shopping mode is disabled in private tabs. [Bug 1847063](https://bugzilla.mozilla.org/show_bug.cgi?id=1847063) * `SessionState.isProductUrl` has been moved to `ContentState.isProductUrl`. [Bug 1857287](https://bugzilla.mozilla.org/show_bug.cgi?id=1857287) -* **support-utils** - * Recognize IPv6 literals in the address bar. [Bug 1803465](https://bugzilla.mozilla.org/show_bug.cgi?id=1803465) - # 119.0 * [Commits](https://github.com/mozilla-mobile/firefox-android/compare/releases_v118..releases_v119) * [Dependencies](https://github.com/mozilla-mobile/firefox-android/blob/releases_v119/android-components/plugins/dependencies/src/main/java/DependenciesPlugin.kt) From 674be27070f77e1d6e55b6bd67f0f456f994bb35 Mon Sep 17 00:00:00 2001 From: Paul Marks Date: Thu, 16 Nov 2023 16:06:16 -0500 Subject: [PATCH 6/9] Bug 1803465 - Reorganize unit tests --- .../support/utils/URLStringUtilsTest.kt | 46 +++++---- .../support/utils/WebURLFinderTest.kt | 93 +++++++++++++++++++ 2 files changed, 123 insertions(+), 16 deletions(-) diff --git a/android-components/components/support/utils/src/test/java/mozilla/components/support/utils/URLStringUtilsTest.kt b/android-components/components/support/utils/src/test/java/mozilla/components/support/utils/URLStringUtilsTest.kt index 069f21b5b4fe..d406e9f15254 100644 --- a/android-components/components/support/utils/src/test/java/mozilla/components/support/utils/URLStringUtilsTest.kt +++ b/android-components/components/support/utils/src/test/java/mozilla/components/support/utils/URLStringUtilsTest.kt @@ -88,21 +88,28 @@ class URLStringUtilsTest { assertFalse(isURLLike("www.c-c- ")) assertFalse(isURLLike("3-3 ")) - // IPv6 literals - assertTrue(isURLLike("[::]")) - assertTrue(isURLLike("[::1]")) - assertTrue(isURLLike("[1::]")) - assertTrue(isURLLike("[::]/")) - assertTrue(isURLLike("[1:2:3:4:5:6:7:8]")) - assertTrue(isURLLike("https:[::]")) - assertTrue(isURLLike("https://[::]")) - assertTrue(isURLLike("https://[::1]")) - assertTrue(isURLLike("https://[1::]")) - assertTrue(isURLLike("https://[2001:db8::1.2.3.4]/")) - assertTrue(isURLLike("https://[1:2:3:4:5:6:7:8]/")) - assertTrue(isURLLike("[2001:db8::1.2.3.4]/")) - - // Invalid IPv6 literals, just to illustrate the limits of the regex. + // Valid IPv6 literals correctly recognized as valid. + val validIPv6Literals = listOf( + "[::]", + "[::1]", + "[1::]", + "[1:2:3:4:5:6:7:8]", + "[2001:db8::1.2.3.4]", + "[::1]:8080", + ) + + validIPv6Literals.forEach { url -> + assertTrue(isURLLike(url)) + assertTrue(isURLLike("$url/")) + assertTrue(isURLLike("https://$url")) + assertTrue(isURLLike("https://$url/")) + assertTrue(isURLLike("https:$url")) + assertTrue(isURLLike("http://$url")) + assertTrue(isURLLike("http://$url/")) + assertTrue(isURLLike("http:$url")) + } + + // Invalid IPv6 literals correctly recognized as invalid. assertFalse(isURLLike("::1")) assertFalse(isURLLike(":::")) assertFalse(isURLLike("[[http://]]")) @@ -110,9 +117,14 @@ class URLStringUtilsTest { assertFalse(isURLLike("[[[:")) assertFalse(isURLLike("[[[:/")) assertFalse(isURLLike("http://]]]")) - assertTrue(isURLLike("[:::")) + + // Invalid IPv6 literals correctly recognized as something else. assertTrue(isURLLike("fe80::")) assertTrue(isURLLike("x:[")) + + // Invalid IPv6 literals incorrectly recognized as valid. + // We allow these for now, until bug 1685152 is fixed. + assertTrue(isURLLike("[:::")) assertTrue(isURLLike("http://[::")) assertTrue(isURLLike("http://[::/path")) assertTrue(isURLLike("http://[::?query")) @@ -121,6 +133,8 @@ class URLStringUtilsTest { assertTrue(isURLLike("[[[::")) assertTrue(isURLLike("[[[::/")) assertTrue(isURLLike("http://[1.2.3]")) + assertTrue(isURLLike("https://[1:2:3:4:5:6:7]/")) + assertTrue(isURLLike("https://[1:2:3:4:5:6:7:8:9]/")) // Examples from issues assertTrue(isURLLike("https://abc--cba.com/")) // #7096 diff --git a/android-components/components/support/utils/src/test/java/mozilla/components/support/utils/WebURLFinderTest.kt b/android-components/components/support/utils/src/test/java/mozilla/components/support/utils/WebURLFinderTest.kt index d523e711d5fa..256e7b7f181d 100644 --- a/android-components/components/support/utils/src/test/java/mozilla/components/support/utils/WebURLFinderTest.kt +++ b/android-components/components/support/utils/src/test/java/mozilla/components/support/utils/WebURLFinderTest.kt @@ -116,4 +116,97 @@ class WebURLFinderTest { assertFalse(isWebURL("javascript:alert('Hi')")) assertFalse(isWebURL("JAVascript:alert('Hi')")) } + + @Test + fun isUrlLikeEmulated() { + // autolinkWebUrlPattern uses a copy of the regex from URLStringUtils, + // so here we emulate isURLLike() and copy its tests. + val isURLLike: (String) -> Boolean = { find(it) == it.trim() } + + // All cases that behave differently are annotated with INVERT(). + val INVERT: (Boolean) -> Boolean = { !it } + + assertFalse(isURLLike("inurl:mozilla.org advanced search")) + assertFalse(isURLLike("sf: help")) + assertFalse(isURLLike("mozilla./~")) + assertFalse(isURLLike("cnn.com politics")) + + assertTrue(isURLLike("about:config")) + assertTrue(isURLLike("about:config:8000")) + assertTrue(INVERT(isURLLike("file:///home/user/myfile.html"))) + assertTrue(INVERT(isURLLike("file://////////////home//user/myfile.html"))) + assertTrue(INVERT(isURLLike("file://C:\\Users\\user\\myfile.html"))) + assertTrue(isURLLike("http://192.168.255.255")) + assertTrue(isURLLike("link.unknown")) + assertTrue(isURLLike("3.14.2019")) + assertTrue(isURLLike("3-four.14.2019")) + assertTrue(isURLLike(" cnn.com ")) + assertTrue(isURLLike(" cnn.com")) + assertTrue(isURLLike("cnn.com ")) + assertTrue(isURLLike("mozilla.com/~userdir")) + assertTrue(isURLLike("my-domain.com")) + assertTrue(isURLLike("http://faß.de//")) + assertTrue(isURLLike("cnn.cơḿ")) + assertTrue(isURLLike("cnn.çơḿ")) + + assertTrue(isURLLike("c-c.com")) + assertTrue(isURLLike("c-c-c-c.c-c-c")) + assertTrue(isURLLike("c-http://c.com")) + assertTrue(isURLLike("about-mozilla:mozilla")) + assertTrue(isURLLike("c-http.d-x")) + assertTrue(isURLLike("www.c.-")) + assertTrue(isURLLike("3-3.3")) + assertTrue(isURLLike("www.c-c.-")) + + assertFalse(isURLLike(" -://x.com ")) + assertFalse(isURLLike(" -x.com")) + assertFalse(isURLLike("http://www-.com")) + assertFalse(isURLLike("www.c-c- ")) + assertFalse(isURLLike("3-3 ")) + + val validIPv6Literals = listOf( + "[::]", + "[::1]", + "[1::]", + "[1:2:3:4:5:6:7:8]", + "[2001:db8::1.2.3.4]", + "[::1]:8080", + ) + + validIPv6Literals.forEach { url -> + assertTrue(INVERT(isURLLike(url))) + assertTrue(INVERT(isURLLike("$url/"))) + assertTrue(isURLLike("https://$url")) + assertTrue(isURLLike("https://$url/")) + assertTrue(isURLLike("https:$url")) + assertTrue(isURLLike("http://$url")) + assertTrue(isURLLike("http://$url/")) + assertTrue(isURLLike("http:$url")) + } + + assertFalse(isURLLike("::1")) + assertFalse(isURLLike(":::")) + assertFalse(isURLLike("[[http://]]")) + assertFalse(isURLLike("[[[")) + assertFalse(isURLLike("[[[:")) + assertFalse(isURLLike("[[[:/")) + assertFalse(isURLLike("http://]]]")) + + assertTrue(isURLLike("fe80::")) + assertTrue(isURLLike("x:[")) + + assertTrue(INVERT(isURLLike("[:::"))) + assertTrue(INVERT(isURLLike("http://[::"))) + assertTrue(INVERT(isURLLike("http://[::/path"))) + assertTrue(INVERT(isURLLike("http://[::?query"))) + assertTrue(INVERT(isURLLike("[[http://banana]]"))) + assertTrue(INVERT(isURLLike("http://[[["))) + assertTrue(INVERT(isURLLike("[[[::"))) + assertTrue(INVERT(isURLLike("[[[::/"))) + assertTrue(INVERT(isURLLike("http://[1.2.3]"))) + assertTrue(INVERT(isURLLike("https://[1:2:3:4:5:6:7]/"))) + assertTrue(INVERT(isURLLike("https://[1:2:3:4:5:6:7:8:9]/"))) + + assertTrue(isURLLike("https://abc--cba.com/")) + } } From 39f09b248b6134e608c41afb761b9902fff85caa Mon Sep 17 00:00:00 2001 From: Paul Marks Date: Fri, 17 Nov 2023 14:48:52 -0500 Subject: [PATCH 7/9] Bug 1803465 - More unit tests --- .../mozilla/components/support/utils/URLStringUtilsTest.kt | 2 ++ .../mozilla/components/support/utils/WebURLFinderTest.kt | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/android-components/components/support/utils/src/test/java/mozilla/components/support/utils/URLStringUtilsTest.kt b/android-components/components/support/utils/src/test/java/mozilla/components/support/utils/URLStringUtilsTest.kt index d406e9f15254..cfd5f68fdbef 100644 --- a/android-components/components/support/utils/src/test/java/mozilla/components/support/utils/URLStringUtilsTest.kt +++ b/android-components/components/support/utils/src/test/java/mozilla/components/support/utils/URLStringUtilsTest.kt @@ -104,9 +104,11 @@ class URLStringUtilsTest { assertTrue(isURLLike("https://$url")) assertTrue(isURLLike("https://$url/")) assertTrue(isURLLike("https:$url")) + assertTrue(isURLLike("https:$url/")) assertTrue(isURLLike("http://$url")) assertTrue(isURLLike("http://$url/")) assertTrue(isURLLike("http:$url")) + assertTrue(isURLLike("http:$url/")) } // Invalid IPv6 literals correctly recognized as invalid. diff --git a/android-components/components/support/utils/src/test/java/mozilla/components/support/utils/WebURLFinderTest.kt b/android-components/components/support/utils/src/test/java/mozilla/components/support/utils/WebURLFinderTest.kt index 256e7b7f181d..28f036317ae0 100644 --- a/android-components/components/support/utils/src/test/java/mozilla/components/support/utils/WebURLFinderTest.kt +++ b/android-components/components/support/utils/src/test/java/mozilla/components/support/utils/WebURLFinderTest.kt @@ -121,7 +121,9 @@ class WebURLFinderTest { fun isUrlLikeEmulated() { // autolinkWebUrlPattern uses a copy of the regex from URLStringUtils, // so here we emulate isURLLike() and copy its tests. - val isURLLike: (String) -> Boolean = { find(it) == it.trim() } + val isURLLike: (String) -> Boolean = { + find("random_text $it other_random_text") == it.trim() + } // All cases that behave differently are annotated with INVERT(). val INVERT: (Boolean) -> Boolean = { !it } @@ -179,9 +181,11 @@ class WebURLFinderTest { assertTrue(isURLLike("https://$url")) assertTrue(isURLLike("https://$url/")) assertTrue(isURLLike("https:$url")) + assertTrue(isURLLike("https:$url/")) assertTrue(isURLLike("http://$url")) assertTrue(isURLLike("http://$url/")) assertTrue(isURLLike("http:$url")) + assertTrue(isURLLike("http:$url/")) } assertFalse(isURLLike("::1")) From 2f6a576601d5aee3038d84172dc5a1ca6a9d7c64 Mon Sep 17 00:00:00 2001 From: Paul Marks Date: Tue, 21 Nov 2023 22:09:57 -0500 Subject: [PATCH 8/9] Bug 1803465 - Replace INVERT() with comments. --- .../support/utils/WebURLFinderTest.kt | 45 +++++++++++-------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/android-components/components/support/utils/src/test/java/mozilla/components/support/utils/WebURLFinderTest.kt b/android-components/components/support/utils/src/test/java/mozilla/components/support/utils/WebURLFinderTest.kt index b1c6206228c0..8f6d270495e9 100644 --- a/android-components/components/support/utils/src/test/java/mozilla/components/support/utils/WebURLFinderTest.kt +++ b/android-components/components/support/utils/src/test/java/mozilla/components/support/utils/WebURLFinderTest.kt @@ -135,9 +135,6 @@ class WebURLFinderTest { find("random_text $it other_random_text") == it.trim() } - // All cases that behave differently are annotated with INVERT(). - val INVERT: (Boolean) -> Boolean = { !it } - assertFalse(isURLLike("inurl:mozilla.org advanced search")) assertFalse(isURLLike("sf: help")) assertFalse(isURLLike("mozilla./~")) @@ -145,9 +142,13 @@ class WebURLFinderTest { assertTrue(isURLLike("about:config")) assertTrue(isURLLike("about:config:8000")) - assertTrue(INVERT(isURLLike("file:///home/user/myfile.html"))) - assertTrue(INVERT(isURLLike("file://////////////home//user/myfile.html"))) - assertTrue(INVERT(isURLLike("file://C:\\Users\\user\\myfile.html"))) + + // These cases differ from the original isUrlLike test because + // file:// is rejected by isInvalidUriScheme. + assertFalse(isURLLike("file:///home/user/myfile.html")) + assertFalse(isURLLike("file://////////////home//user/myfile.html")) + assertFalse(isURLLike("file://C:\\Users\\user\\myfile.html")) + assertTrue(isURLLike("http://192.168.255.255")) assertTrue(isURLLike("link.unknown")) assertTrue(isURLLike("3.14.2019")) @@ -186,8 +187,11 @@ class WebURLFinderTest { ) validIPv6Literals.forEach { url -> - assertTrue(INVERT(isURLLike(url))) - assertTrue(INVERT(isURLLike("$url/"))) + // These cases differ from the original isUrlLike test because + // java.net.URI doesn't recognize bare IPv6 literals. + assertFalse(isURLLike(url)) + assertFalse(isURLLike("$url/")) + assertTrue(isURLLike("https://$url")) assertTrue(isURLLike("https://$url/")) assertTrue(isURLLike("https:$url")) @@ -209,17 +213,20 @@ class WebURLFinderTest { assertTrue(isURLLike("fe80::")) assertTrue(isURLLike("x:[")) - assertTrue(INVERT(isURLLike("[:::"))) - assertTrue(INVERT(isURLLike("http://[::"))) - assertTrue(INVERT(isURLLike("http://[::/path"))) - assertTrue(INVERT(isURLLike("http://[::?query"))) - assertTrue(INVERT(isURLLike("[[http://banana]]"))) - assertTrue(INVERT(isURLLike("http://[[["))) - assertTrue(INVERT(isURLLike("[[[::"))) - assertTrue(INVERT(isURLLike("[[[::/"))) - assertTrue(INVERT(isURLLike("http://[1.2.3]"))) - assertTrue(INVERT(isURLLike("https://[1:2:3:4:5:6:7]/"))) - assertTrue(INVERT(isURLLike("https://[1:2:3:4:5:6:7:8:9]/"))) + // These cases differ from the original isUrlLike test because + // the regex is just an approximation. When bug 1685152 is fixed, + // the original isURLLike will also return false. + assertFalse(isURLLike("[:::")) + assertFalse(isURLLike("http://[::")) + assertFalse(isURLLike("http://[::/path")) + assertFalse(isURLLike("http://[::?query")) + assertFalse(isURLLike("[[http://banana]]")) + assertFalse(isURLLike("http://[[[")) + assertFalse(isURLLike("[[[::")) + assertFalse(isURLLike("[[[::/")) + assertFalse(isURLLike("http://[1.2.3]")) + assertFalse(isURLLike("https://[1:2:3:4:5:6:7]/")) + assertFalse(isURLLike("https://[1:2:3:4:5:6:7:8:9]/")) assertTrue(isURLLike("https://abc--cba.com/")) } From 9591c66a1b5ff667b7d688212d59b275dd2726a2 Mon Sep 17 00:00:00 2001 From: Jonathan Almeida Date: Wed, 22 Nov 2023 18:44:52 +0400 Subject: [PATCH 9/9] Bug 1803465 - Update changelog --- docs/changelog.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/changelog.md b/docs/changelog.md index e2eeed09add9..0706c5c5905e 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -10,6 +10,9 @@ permalink: /changelog/ * [Gecko](https://github.com/mozilla-mobile/firefox-android/blob/main/android-components/plugins/dependencies/src/main/java/Gecko.kt) * [Configuration](https://github.com/mozilla-mobile/firefox-android/blob/main/android-components/.config.yml) +* **support-utils** + * Recognize IPv6 literals in the address bar. [Bug 1803465](https://bugzilla.mozilla.org/show_bug.cgi?id=1803465) + # 121.0 * [Commits](https://github.com/mozilla-mobile/firefox-android/compare/releases_v120..releases_v121) * [Dependencies](https://github.com/mozilla-mobile/firefox-android/blob/releases_v121/android-components/plugins/dependencies/src/main/java/DependenciesPlugin.kt) @@ -28,9 +31,6 @@ permalink: /changelog/ * **feature-search** * `RegionManager` now uses the cached result from it's `LocationService`. [Bug 1854988](https://bugzilla.mozilla.org/show_bug.cgi?id=1854988) -* **support-utils** - * Recognize IPv6 literals in the address bar. [Bug 1803465](https://bugzilla.mozilla.org/show_bug.cgi?id=1803465) - # 120.0 * [Commits](https://github.com/mozilla-mobile/firefox-android/compare/releases_v119..releases_v120) * [Dependencies](https://github.com/mozilla-mobile/firefox-android/blob/releases_v120/android-components/plugins/dependencies/src/main/java/DependenciesPlugin.kt) @@ -56,7 +56,7 @@ permalink: /changelog/ * **feature-tabs** * Removed deprecated `TabsUseCases.AddNewPrivateTabUseCase`. [Bug 1853070](https://bugzilla.mozilla.org/show_bug.cgi?id=1853070) - + * **lib-crash-sentry** * `SentryService.initIfNeeded` is now public. [bug #1851676](https://bugzilla.mozilla.org/show_bug.cgi?id=1851676)