Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions punycode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
5 changes: 5 additions & 0 deletions tests/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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': [
Expand Down