Skip to content

Commit

Permalink
Empty strings now returns error cause its not valid XML
Browse files Browse the repository at this point in the history
  • Loading branch information
d3adc0d3 authored and Leonidas-from-XIV committed Mar 22, 2017
1 parent 8374f68 commit b9b44e0
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/bom.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/builder.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/defaults.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions lib/parser.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/processors.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/xml2js.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/parser.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ class exports.Parser extends events.EventEmitter
try
str = str.toString()
if str.trim() is ''
@emit "end", null
return true
@emit 'error', new Error "Empty string is not valid XML"
return

str = bom.stripBOM str
if @options.async
Expand Down
7 changes: 5 additions & 2 deletions test/parser.test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,11 @@ module.exports =
'test empty tag result specified null': skeleton(emptyTag: null, (r) ->
equ r.sample.emptytest[0], null)

'test invalid empty XML file': skeleton(__xmlString: ' ', (r) ->
equ r, null)
'test invalid empty XML file': (test) ->
x2js = new xml2js.Parser()
x2js.parseString '', (err, r) ->
assert.notEqual err, null
test.finish()

'test enabled normalizeTags': skeleton(normalizeTags: true, (r) ->
console.log 'Result object: ' + util.inspect r, false, 10
Expand Down

0 comments on commit b9b44e0

Please sign in to comment.