mathiasbynens / punycode.js

A robust Punycode converter that fully complies to RFC 3492 and RFC 5891.
https://mths.be/punycode
MIT License
1.6k stars 159 forks source link

IE 8 toUnicode #17

Closed gsmlg closed 10 years ago

gsmlg commented 10 years ago

If the domain name ends with a ., in IE8 the last . will be removed by toUnicode.

gsmlg commented 10 years ago

I've found out why.

"abc.com.".split('.') in IE 8 will return ['abc','com', undefined]

"abc.com.".split(/\x2E/) in IE 8 will return ['abc', 'com'].

This only happens when using split with a regular expression.

tomowang commented 10 years ago

Using string instead of regex for split. Here is quick fix:

diff --git a/punycode.js b/punycode.js
index a9999d8..db0a17f 100644
--- a/punycode.js
+++ b/punycode.js
@@ -103,7 +103,8 @@
                        result = parts[0] + '@';
                        string = parts[1];
                }
-               var labels = string.split(regexSeparators);
+        string = string.replace(regexSeparators, '\x2E');
+               var labels = string.split('.');
                var encoded = map(labels, fn).join('.');
                return result + encoded;
        }