From 1749746dd8b77f7ed98bcb11956fafe3702d0dc5 Mon Sep 17 00:00:00 2001 From: Pete Jihoon Kim Date: Sun, 3 Dec 2017 20:55:08 -0800 Subject: [PATCH] Fix handling of ens domains containing international characters --- index.js | 2 +- test/index.js | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 939e751..b301109 100644 --- a/index.js +++ b/index.js @@ -23,7 +23,7 @@ function namehash (inputName) { } function normalize(name) { - return name ? uts46.toUnicode(name, {useStd3ASCII: true, transitional: false}) : name + return name ? uts46.toAscii(name, {useStd3ASCII: true, transitional: false}) : name } exports.hash = namehash diff --git a/test/index.js b/test/index.js index 6d93725..71b5db0 100644 --- a/test/index.js +++ b/test/index.js @@ -35,10 +35,20 @@ test('foo.eth', (t) => { t.equal(output, expected) }) -test('normalize', (t) => { +test('normalize ascii domain', (t) => { t.plan(1) - const input = 'foo.eth' + const input = 'foo.eth' // latin chars only const expected = 'foo.eth' const output = namehash.normalize(input) t.equal(output, expected) }) + + +test('normalize international domain', (t) => { + t.plan(1) + const input = 'fоо.eth' // with cyrillic 'o' + const expected = 'xn--f-1tba.eth' + const output = namehash.normalize(input) + t.equal(output, expected) +}) +