diff --git a/punycode.js b/punycode.js index 752b98a..5ba63b4 100644 --- a/punycode.js +++ b/punycode.js @@ -70,13 +70,13 @@ function map(array, callback) { * function. */ function mapDomain(domain, callback) { - const parts = domain.split('@'); + const atPos = domain.lastIndexOf('@'); let result = ''; - if (parts.length > 1) { + if (atPos > -1) { // In email addresses, only the domain name should be punycoded. Leave // the local part (i.e. everything up to `@`) intact. - result = parts[0] + '@'; - domain = parts[1]; + result = domain.substring(0, atPos + 1); + domain = domain.substring(atPos + 1); } // Avoid `split(regex)` for IE8 compatibility. See #17. domain = domain.replace(regexSeparators, '\x2E'); diff --git a/tests/tests.js b/tests/tests.js index ced85a0..8eb0a3f 100644 --- a/tests/tests.js +++ b/tests/tests.js @@ -216,6 +216,11 @@ const testData = { { // https://github.com/mathiasbynens/punycode.js/pull/115 'decoded': 'foo\x7F.example', 'encoded': 'foo\x7F.example' + }, + { + "description": "Email address that includes multiple at signs", + "decoded": "\"very.(),:;<>[]\\\".VERY.\\\"@very@\\ \\\"very\\\".unusual\"@\uD83D\uDCA9.la", + "encoded": "\"very.(),:;<>[]\\\".VERY.\\\"@very@\\ \\\"very\\\".unusual\"@xn--ls8h.la" } ], 'separators': [