Skip to content

Commit

Permalink
fix: raise an error if the document does not have a root
Browse files Browse the repository at this point in the history
  • Loading branch information
lddubeau committed Jul 6, 2018
1 parent 7611a85 commit f2de520
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 15 deletions.
3 changes: 3 additions & 0 deletions lib/saxes.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ class SAXParser {
/* eslint-enable class-methods-use-this */

end() {
if (!this.sawRoot) {
this.fail("Document must contain a root element");
}
if (this.sawRoot && !this.closedRoot) {
this.fail("Unclosed root tag");
}
Expand Down
4 changes: 3 additions & 1 deletion test/end_empty_stream.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
"use strict";

const { expect } = require("chai");
const saxes = require("../lib/saxes");

it("end empty stream", () => {
const saxesStream = saxes.createStream();
// It musn't throw.
saxesStream.end();
expect(() => saxesStream.end()).to.throw(Error,
/Document must contain a root element/);
});
14 changes: 0 additions & 14 deletions test/stand-alone-comment.js

This file was deleted.

0 comments on commit f2de520

Please sign in to comment.