Permalink
Browse files

ensure that parser is closed when parsing a string, to guarantee well…

… formed but not closed XML generates an error
  • Loading branch information...
tsgautier committed Dec 6, 2013
1 parent 23b4776 commit 8d1a9a65dd33d8d638d22cfdf1c3ef8490732b0d
Showing with 12 additions and 4 deletions.
  1. +1 −1 lib/xml2js.js
  2. +1 −1 src/xml2js.coffee
  3. +10 −2 test/parser.test.coffee
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -299,7 +299,7 @@ class exports.Parser extends events.EventEmitter
@emit "end", null
return true
- @saxParser.write bom.stripBOM str.toString()
+ @saxParser.write(bom.stripBOM str.toString()).close()
exports.parseString = (str, a, b) ->
# let's determine what we got as arguments
View
@@ -285,8 +285,10 @@ module.exports =
throw new Error 'error throwing in callback'
throw new Error 'error throwing outside'
catch e
- # don't catch the exception that was thrown by callback
- equ e.message, 'error throwing outside'
+ # the stream is finished by the time the parseString method is called
+ # so the callback, which is synchronous, will bubble the inner error
+ # out to here, make sure that happens
+ equ e.message, 'error throwing in callback'
test.finish()
'test xmlns': skeleton(xmlns: true, (r) ->
@@ -340,3 +342,9 @@ module.exports =
equ err, null
assert.deepEqual resWithNew, resWithoutNew
test.done()
+
+ 'test not closed but well formed xml': (test) ->
+ xml = "<test>"
+ xml2js.parseString xml, (err, parsed) ->
+ assert.equal err.message, 'Unclosed root tag\nLine: 0\nColumn: 6\nChar: '
+ test.finish()

0 comments on commit 8d1a9a6

Please sign in to comment.