From bbf929a8a54f0d012bdc44cbe622fdeda2509230 Mon Sep 17 00:00:00 2001 From: oozcitak Date: Thu, 8 Feb 2018 10:48:28 -0500 Subject: [PATCH] Simpler regex while validating encoding string --- src/XMLStringifier.coffee | 2 +- test/issues/encoding.coffee | 13 +++++++++++++ test/mocha.opts | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 test/issues/encoding.coffee diff --git a/src/XMLStringifier.coffee b/src/XMLStringifier.coffee index 663945b..1944f4a 100644 --- a/src/XMLStringifier.coffee +++ b/src/XMLStringifier.coffee @@ -49,7 +49,7 @@ module.exports = class XMLStringifier val xmlEncoding: (val) -> val = '' + val or '' - if not val.match /^[A-Za-z](?:[A-Za-z0-9._-]|-)*$/ + if not val.match /^[A-Za-z](?:[A-Za-z0-9._-])*$/ throw new Error "Invalid encoding: " + val val xmlStandalone: (val) -> diff --git a/test/issues/encoding.coffee b/test/issues/encoding.coffee new file mode 100644 index 0000000..654af83 --- /dev/null +++ b/test/issues/encoding.coffee @@ -0,0 +1,13 @@ +suite 'Tests specific to issues:', -> + test 'ReDos', -> + eq( + xml('root', {encoding: 'UTF-8'}).end() + '' + ) + + err( + () -> xml('root', {encoding: 'A------------------------------------!'}) + /Invalid encoding: A------------------------------------!/ + ) + + diff --git a/test/mocha.opts b/test/mocha.opts index b57fea1..ac55223 100644 --- a/test/mocha.opts +++ b/test/mocha.opts @@ -1,4 +1,4 @@ - --compilers coffee:coffee-script/register + --compilers coffee:coffeescript/register --require coffee-coverage/register-istanbul --require test/common --ui tdd