From 9fc17d58695baf0ead851ebc28bd131ad9ca8c55 Mon Sep 17 00:00:00 2001 From: Jesse Tane Date: Sun, 5 Jan 2014 17:17:55 -0500 Subject: [PATCH] add failing utf16 surrogate pair test --- test/buffer.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/test/buffer.js b/test/buffer.js index 63e7e8c..1b0ec7d 100644 --- a/test/buffer.js +++ b/test/buffer.js @@ -261,3 +261,37 @@ test('base64 strings without padding', function (t) { t.equal((new B('YW9ldQ', 'base64').toString()), 'aoeu') t.end() }) + +test('detect utf16 surrogate pairs', function(t) { + t.plan(1) + var text = '😸💭👍' + var buf = new B(text) + t.equal(text, buf.toString()) + t.end() +}) + +test('throw on orphaned utf16 surrogate lead code point', function(t) { + t.plan(1) + var text = 'í ½í ½í²­í ½í±' + var err + try { + var buf = new B(text) + } catch (e) { + err = e + } + t.equal(err instanceof URIError, true) + t.end() +}) + +test('throw on orphaned utf16 surrogate trail code point', function(t) { + t.plan(1) + var text = 'í ½í¸¸í ½í²­í±' + var err + try { + var buf = new B(text) + } catch (e) { + err = e + } + t.equal(err instanceof URIError, true) + t.end() +}) -- 2.34.1