From 392f09c2baa8b624507fcb0d330423b841de6c2c Mon Sep 17 00:00:00 2001 From: Anthony Date: Tue, 30 Apr 2024 22:56:06 +0800 Subject: [PATCH] updated idna.js --- scripts/idna.js | 58 ++++++++++++++++++++++--------------------------- 1 file changed, 26 insertions(+), 32 deletions(-) diff --git a/scripts/idna.js b/scripts/idna.js index 2094b6b..a27bb31 100644 --- a/scripts/idna.js +++ b/scripts/idna.js @@ -1,6 +1,9 @@ -// http://stackoverflow.com/questions/183485/can-anyone-recommend-a-good-free-javascript-for-punycode-to-unicode-conversion //Javascript Punycode converter derived from example in RFC3492. //This implementation is created by some@domain.name and released into public domain + +var domains = getParam("domains", ""), + parsed = []; + var punycode = new function Punycode() { // This object converts to and from puny-code used in IDN // @@ -91,7 +94,7 @@ var punycode = new function Punycode() { delta += Math.floor(delta / numpoints); for (k = 0; delta > (((base - tmin) * tmax) >> 1); k += base) { - delta = Math.floor(delta / ( base - tmin )); + delta = Math.floor(delta / ( base - tmin )); } return Math.floor(k + (base - tmin + 1) * delta / (delta + skew)); } @@ -148,24 +151,24 @@ var punycode = new function Punycode() { // if we increase i as we go, then subtract off its starting // value at the end to obtain delta. for (oldi = i, w = 1, k = base; ; k += base) { - if (ic >= input_length) { - throw RangeError ("punycode_bad_input(1)"); - } - digit = decode_digit(input.charCodeAt(ic++)); + if (ic >= input_length) { + throw RangeError ("punycode_bad_input(1)"); + } + digit = decode_digit(input.charCodeAt(ic++)); - if (digit >= base) { - throw RangeError("punycode_bad_input(2)"); - } - if (digit > Math.floor((maxint - i) / w)) { - throw RangeError ("punycode_overflow(1)"); - } - i += digit * w; - t = k <= bias ? tmin : k >= bias + tmax ? tmax : k - bias; - if (digit < t) { break; } - if (w > Math.floor(maxint / (base - t))) { - throw RangeError("punycode_overflow(2)"); - } - w *= (base - t); + if (digit >= base) { + throw RangeError("punycode_bad_input(2)"); + } + if (digit > Math.floor((maxint - i) / w)) { + throw RangeError ("punycode_overflow(1)"); + } + i += digit * w; + t = k <= bias ? tmin : k >= bias + tmax ? tmax : k - bias; + if (digit < t) { break; } + if (w > Math.floor(maxint / (base - t))) { + throw RangeError("punycode_overflow(2)"); + } + w *= (base - t); } out = output.length + 1; @@ -320,19 +323,10 @@ var punycode = new function Punycode() { } }(); -var sEnvUrl = "${env.url}", - sConverted = sEnvUrl.split('.')[0], - sDomain, - sResp; +domains = domains.split(','); - -if (sConverted) { - if (/[а-яА-ЯЁё]/.test(sConverted)) { - sDomain = sConverted.split('//')[1]; - sConverted = punycode.ToASCII(sDomain); - } +for (var i = 0, n = domains.length; i < n; i++) { + parsed.push(punycode.ToASCII(String(java.lang.String(domains[i]).trim()))); } -sResp = sEnvUrl.replace(sDomain, sConverted).split('/')[2]; - -return {result: 0, domain: sResp} \ No newline at end of file +return { result: 0, domains: parsed } \ No newline at end of file