diff --git a/lib/saxes.js b/lib/saxes.js index 4eb6dd22..3e7717ac 100644 --- a/lib/saxes.js +++ b/lib/saxes.js @@ -930,9 +930,7 @@ class SaxesParser { const c = this.getChar(chunkState); if (c === "-") { this.state = S_COMMENT_ENDED; - if (this.comment) { - this.emitNode("oncomment", this.comment); - } + this.emitNode("oncomment", this.comment); this.comment = ""; } else { diff --git a/test/comment.js b/test/comment.js new file mode 100644 index 00000000..7cc01c34 --- /dev/null +++ b/test/comment.js @@ -0,0 +1,13 @@ +"use strict"; + +require(".").test({ + name: "comment", + xml: "", + expect: [ + ["opentagstart", { name: "r", attributes: {} }], + ["opentag", { name: "r", attributes: {}, isSelfClosing: false }], + ["comment", "foo"], + ["comment", ""], + ["closetag", "r"], + ], +});