updated idna.js

main
Anthony 2024-04-30 22:56:06 +08:00
parent a67e1dd285
commit 392f09c2ba
1 changed files with 26 additions and 32 deletions

View File

@ -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. //Javascript Punycode converter derived from example in RFC3492.
//This implementation is created by some@domain.name and released into public domain //This implementation is created by some@domain.name and released into public domain
var domains = getParam("domains", ""),
parsed = [];
var punycode = new function Punycode() { var punycode = new function Punycode() {
// This object converts to and from puny-code used in IDN // 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); delta += Math.floor(delta / numpoints);
for (k = 0; delta > (((base - tmin) * tmax) >> 1); k += base) { 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)); 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 // if we increase i as we go, then subtract off its starting
// value at the end to obtain delta. // value at the end to obtain delta.
for (oldi = i, w = 1, k = base; ; k += base) { for (oldi = i, w = 1, k = base; ; k += base) {
if (ic >= input_length) { if (ic >= input_length) {
throw RangeError ("punycode_bad_input(1)"); throw RangeError ("punycode_bad_input(1)");
} }
digit = decode_digit(input.charCodeAt(ic++)); digit = decode_digit(input.charCodeAt(ic++));
if (digit >= base) { if (digit >= base) {
throw RangeError("punycode_bad_input(2)"); throw RangeError("punycode_bad_input(2)");
} }
if (digit > Math.floor((maxint - i) / w)) { if (digit > Math.floor((maxint - i) / w)) {
throw RangeError ("punycode_overflow(1)"); throw RangeError ("punycode_overflow(1)");
} }
i += digit * w; i += digit * w;
t = k <= bias ? tmin : k >= bias + tmax ? tmax : k - bias; t = k <= bias ? tmin : k >= bias + tmax ? tmax : k - bias;
if (digit < t) { break; } if (digit < t) { break; }
if (w > Math.floor(maxint / (base - t))) { if (w > Math.floor(maxint / (base - t))) {
throw RangeError("punycode_overflow(2)"); throw RangeError("punycode_overflow(2)");
} }
w *= (base - t); w *= (base - t);
} }
out = output.length + 1; out = output.length + 1;
@ -320,19 +323,10 @@ var punycode = new function Punycode() {
} }
}(); }();
var sEnvUrl = "${env.url}", domains = domains.split(',');
sConverted = sEnvUrl.split('.')[0],
sDomain,
sResp;
for (var i = 0, n = domains.length; i < n; i++) {
if (sConverted) { parsed.push(punycode.ToASCII(String(java.lang.String(domains[i]).trim())));
if (/[а-яА-ЯЁё]/.test(sConverted)) {
sDomain = sConverted.split('//')[1];
sConverted = punycode.ToASCII(sDomain);
}
} }
sResp = sEnvUrl.replace(sDomain, sConverted).split('/')[2]; return { result: 0, domains: parsed }
return {result: 0, domain: sResp}