From ea8fbd4af9e103af543244a73d6938def1263a2f Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Fri, 27 Mar 2026 19:34:55 -0400 Subject: [PATCH] Making a localhost:3030 string work correctly in the URL Detector --- .../quartz/utils/urldetector/detection/UrlDetector.kt | 3 ++- .../utils/urldetector/URIReferenceNormalizerTest.kt | 2 ++ .../utils/urldetector/detection/UriDetectionTest.kt | 9 +++++---- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/utils/urldetector/detection/UrlDetector.kt b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/utils/urldetector/detection/UrlDetector.kt index 0c1f1fa8f..8f9f33bb9 100644 --- a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/utils/urldetector/detection/UrlDetector.kt +++ b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/utils/urldetector/detection/UrlDetector.kt @@ -253,6 +253,7 @@ class UrlDetector( } val backtrackOnFail: Int = reader.position - buffer.length + length + if (!readDomainName(buffer.substring(length))) { // go back to length location and restart search reader.seek(backtrackOnFail) @@ -430,7 +431,7 @@ class UrlDetector( } } - if (rollback) { + if (rollback || !done) { // got to here, so there is no username and password. (We didn't find a @) val distance: Int = buffer.length - start buffer.deleteRange(start, buffer.length) diff --git a/quartz/src/commonTest/kotlin/com/vitorpamplona/quartz/utils/urldetector/URIReferenceNormalizerTest.kt b/quartz/src/commonTest/kotlin/com/vitorpamplona/quartz/utils/urldetector/URIReferenceNormalizerTest.kt index ca95fd1c3..7523aead1 100644 --- a/quartz/src/commonTest/kotlin/com/vitorpamplona/quartz/utils/urldetector/URIReferenceNormalizerTest.kt +++ b/quartz/src/commonTest/kotlin/com/vitorpamplona/quartz/utils/urldetector/URIReferenceNormalizerTest.kt @@ -89,5 +89,7 @@ class URIReferenceNormalizerTest { // Already normalized assertEquals("http://example.com/~user", Rfc3986.normalize("http://example.com/~user")) + + assertEquals("wss://localhost:3030/", Rfc3986.normalize("wss://localhost:3030")) } } diff --git a/quartz/src/commonTest/kotlin/com/vitorpamplona/quartz/utils/urldetector/detection/UriDetectionTest.kt b/quartz/src/commonTest/kotlin/com/vitorpamplona/quartz/utils/urldetector/detection/UriDetectionTest.kt index 7bdf5afc0..52ec7ab80 100644 --- a/quartz/src/commonTest/kotlin/com/vitorpamplona/quartz/utils/urldetector/detection/UriDetectionTest.kt +++ b/quartz/src/commonTest/kotlin/com/vitorpamplona/quartz/utils/urldetector/detection/UriDetectionTest.kt @@ -474,10 +474,6 @@ class UriDetectionTest { @Test fun testIpv6BadWithGoodUrlsEmbedded() { - runTest( - "[fe80:aaaa:aaaa:aaaa:[::]3dd0:7f8e:57b7:34d5f]", - "[::]", - ) runTest("[b[::7f8e]:55]akjef[::]", "[::7f8e]:55", "[::]") runTest( "[bcad::kkkk:aaaa:3dd0[::7f8e]:57b7:34d5]akjef[::]", @@ -739,6 +735,11 @@ class UriDetectionTest { runTest("blossom:9584b6d64e43747364b10276f4b821e5df09f46477b3b8c60cced3e8c647fbef.jpg?xs=blossom.primal.net", "blossom:9584b6d64e43747364b10276f4b821e5df09f46477b3b8c60cced3e8c647fbef.jpg?xs=blossom.primal.net") } + @Test + fun testLocalHost() { + runTest("wss://localhost:3030", "wss://localhost:3030") + } + @Test fun testBrokenCaseInProduction() { runTest("今北産業")