Skip to content

Commit

Permalink
fix when comment has '-->'
Browse files Browse the repository at this point in the history
  • Loading branch information
amitguptagwl committed Feb 4, 2022
1 parent 76a3b36 commit 9ff2040
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion spec/comments_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ describe("Comments", function() {
<student>
<!--Student details-->
<!--A second comment-->
<!-- A third comment -->
<name>Tanmay</name>
<!-->> ISO DICTIONARY TYPES <<-->
<grade>A</grade>
</student>
</class_list>`;
Expand All @@ -23,13 +25,14 @@ describe("Comments", function() {
};
const parser = new XMLParser(options);
let result = parser.parse(XMLdata);
// console.log(JSON.stringify(result, null,4));
// console.log(JSON.stringify(result, null,4));

const builder = new XMLBuilder(options);
const output = builder.build(result);
// console.log(output);
expect(output.replace(/\s+/g, "")).toEqual(XMLdata.replace(/\s+/g, ""));
});



});
Expand Down
2 changes: 1 addition & 1 deletion src/xmlparser/OrderedObjParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ const parseXml = function(xmlData) {

i = tagData.closeIndex + 1;
} else if(xmlData.substr(i + 1, 3) === '!--') {
const endIndex = findClosingIndex(xmlData, "-->", i, "Comment is not closed.")
const endIndex = findClosingIndex(xmlData, "-->", i+4, "Comment is not closed.")
if(this.options.commentPropName){
const comment = xmlData.substring(i + 4, endIndex - 2);

Expand Down

0 comments on commit 9ff2040

Please sign in to comment.