diff options
| author | bptato <nincsnevem662@gmail.com> | 2024-10-06 19:25:58 +0200 |
|---|---|---|
| committer | bptato <nincsnevem662@gmail.com> | 2024-10-06 20:22:01 +0200 |
| commit | c9cb63074160fd52dd061f82b9132bdc7e720d2b (patch) | |
| tree | ec26ae0e3572afa5d6cf089ff2a20cd946ff6b97 | |
| parent | 7bfcef1bb2538d6fde0cf6bc589bff705207fa8e (diff) | |
| download | chawan-c9cb63074160fd52dd061f82b9132bdc7e720d2b.tar.gz | |
url: fix IDNA bugs
| -rw-r--r-- | src/types/url.nim | 4 | ||||
| -rw-r--r-- | test/js/url.html | 2 |
2 files changed, 4 insertions, 2 deletions
diff --git a/src/types/url.nim b/src/types/url.nim index 72e817c1..756bf344 100644 --- a/src/types/url.nim +++ b/src/types/url.nim @@ -345,7 +345,7 @@ func processIdna(str: string; beStrict: bool): string = let r = unicode_general_category(addr cr, "Mark") assert r == 0 var labels = "" - for label in ($mapped).split('.'): + for label in mapped.toUTF8().split('.'): if label.startsWith("xn--"): try: let s = punycode.decode(label.substr("xn--".len)) @@ -386,7 +386,7 @@ func unicodeToAscii(s: string; beStrict: bool): string = var all = 0 for label in processed.split('.'): var s = "" - if AllChars - Ascii in s: + if AllChars - Ascii in label: try: s = "xn--" & punycode.encode(label) except PunyError: diff --git a/test/js/url.html b/test/js/url.html index 0a6e0b9e..48e68083 100644 --- a/test/js/url.html +++ b/test/js/url.html @@ -32,6 +32,8 @@ assert_equals(new URL(" h\nt\tt\np\ts\n:\t/\n/\tu\ns\ne\nr\nn\na\n\nm\ne\n:\np\ assert_equals(new URL("abcd?efgh", "https://example.com/") + "", "https://example.com/abcd?efgh"); assert_equals(new URL("abcd#ijkl", "https://example.com/") + "", "https://example.com/abcd#ijkl"); assert_equals(new URL("abcd?efgh#ijkl", "https://example.com/") + "", "https://example.com/abcd?efgh#ijkl"); +assert_equals(new URL("https://ใในใ") + "", "https://xn--zckzah/"); +assert_equals(new URL("https://xn--zckzah") + "", "https://xn--zckzah/"); { const x = new URL("file:/test"); x.protocol = "abcd"; |