Skip to content

Commit

Permalink
Simpler regex while validating encoding string
Browse files Browse the repository at this point in the history
  • Loading branch information
oozcitak committed Feb 8, 2018
1 parent e524ae2 commit bbf929a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/XMLStringifier.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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) ->
Expand Down
13 changes: 13 additions & 0 deletions test/issues/encoding.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
suite 'Tests specific to issues:', ->
test 'ReDos', ->
eq(
xml('root', {encoding: 'UTF-8'}).end()
'<?xml version="1.0" encoding="UTF-8"?><root/>'
)

err(
() -> xml('root', {encoding: 'A------------------------------------!'})
/Invalid encoding: A------------------------------------!/
)


2 changes: 1 addition & 1 deletion test/mocha.opts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
--compilers coffee:coffee-script/register
--compilers coffee:coffeescript/register
--require coffee-coverage/register-istanbul
--require test/common
--ui tdd
Expand Down

0 comments on commit bbf929a

Please sign in to comment.