Skip to content

Commit 7f0732c

Browse files
committed
email address parsing correction
1 parent baa6683 commit 7f0732c

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

punycode.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@ function map(array, callback) {
7070
* function.
7171
*/
7272
function mapDomain(domain, callback) {
73-
const parts = domain.split('@');
73+
const atPos = domain.lastIndexOf('@');
7474
let result = '';
75-
if (parts.length > 1) {
75+
if (atPos > -1) {
7676
// In email addresses, only the domain name should be punycoded. Leave
7777
// the local part (i.e. everything up to `@`) intact.
78-
result = parts[0] + '@';
79-
domain = parts[1];
78+
result = domain.substring(0, atPos + 1);
79+
domain = domain.substring(atPos + 1);
8080
}
8181
// Avoid `split(regex)` for IE8 compatibility. See #17.
8282
domain = domain.replace(regexSeparators, '\x2E');

tests/tests.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,11 @@ const testData = {
216216
{ // https://github.com/mathiasbynens/punycode.js/pull/115
217217
'decoded': 'foo\x7F.example',
218218
'encoded': 'foo\x7F.example'
219+
},
220+
{
221+
"description": "Email address that includes multiple at signs",
222+
"decoded": "\"very.(),:;<>[]\\\".VERY.\\\"@very@\\ \\\"very\\\".unusual\"@\uD83D\uDCA9.la",
223+
"encoded": "\"very.(),:;<>[]\\\".VERY.\\\"@very@\\ \\\"very\\\".unusual\"@xn--ls8h.la"
219224
}
220225
],
221226
'separators': [

0 commit comments

Comments
 (0)