Skip to content
Snippets Groups Projects
Commit 576e4229 authored by Marcus Comstedt's avatar Marcus Comstedt
Browse files

This should be more according to the standard...

Rev: lib/modules/Standards.pmod/IDNA.pmod:1.5
parent e01fa4ee
No related branches found
No related tags found
No related merge requests found
...@@ -380,8 +380,10 @@ string to_ascii(string s, int(0..1)|void allow_unassigned, ...@@ -380,8 +380,10 @@ string to_ascii(string s, int(0..1)|void allow_unassigned,
int(0..1)|void use_std3_ascii_rules) int(0..1)|void use_std3_ascii_rules)
{ {
int is_ascii = max(@values(s)) < 128; int is_ascii = max(@values(s)) < 128;
if(!is_ascii) if(!is_ascii) {
s = nameprep(s, allow_unassigned); s = nameprep(s, allow_unassigned);
is_ascii = max(@values(s)) < 128;
}
if(use_std3_ascii_rules) { if(use_std3_ascii_rules) {
if(array_sscanf(s, "%*[^\0-,./:-@[-`{-\x7f]%n")[0] != sizeof(s)) if(array_sscanf(s, "%*[^\0-,./:-@[-`{-\x7f]%n")[0] != sizeof(s))
error("Label is not valid accoring to STD3: non-LDH codepoint\n"); error("Label is not valid accoring to STD3: non-LDH codepoint\n");
...@@ -409,18 +411,19 @@ string to_ascii(string s, int(0..1)|void allow_unassigned, ...@@ -409,18 +411,19 @@ string to_ascii(string s, int(0..1)|void allow_unassigned,
//! The sequence of Unicode code points to transform. //! The sequence of Unicode code points to transform.
string to_unicode(string s) string to_unicode(string s)
{ {
string s0 = s;
if(max(@values(s)) >= 128 && if(max(@values(s)) >= 128 &&
catch(s = nameprep(s, 1))) catch(s = nameprep(s, 1)))
return s; return s0;
if(lower_case(s[..3]) != "xn--") if(lower_case(s[..3]) != "xn--")
return s; return s0;
string orig_s = s; string ascii_s = s;
catch { catch {
s = Punycode->decode(s[4..]); s = Punycode->decode(s[4..]);
if(lower_case(to_ascii(s, 1)) == lower_case(orig_s)) if(lower_case(to_ascii(s, 1)) == lower_case(ascii_s))
return s; return s;
}; };
return orig_s; return s0;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment