Skip to content

Commit 4c8651f

Browse files
committed
make unpaired tags as Set
1 parent 217c46a commit 4c8651f

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

src/xmlparser/OptionsBuilder.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ export const buildOptions = function (options) {
142142

143143
// Always normalize processEntities for backward compatibility and validation
144144
built.processEntities = normalizeProcessEntities(built.processEntities);
145-
145+
built.unpairedTagsSet = new Set(built.unpairedTags);
146146
// Convert old-style stopNodes for backward compatibility
147147
if (built.stopNodes && Array.isArray(built.stopNodes)) {
148148
built.stopNodes = built.stopNodes.map(node => {

src/xmlparser/OrderedObjParser.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -330,10 +330,10 @@ const parseXml = function (xmlData) {
330330

331331
//check if last tag of nested tag was unpaired tag
332332
const lastTagName = this.matcher.getCurrentTag();
333-
if (tagName && this.options.unpairedTags.indexOf(tagName) !== -1) {
333+
if (tagName && this.options.unpairedTagsSet.has(tagName)) {
334334
throw new Error(`Unpaired tag can not be used as closing tag: </${tagName}>`);
335335
}
336-
if (lastTagName && this.options.unpairedTags.indexOf(lastTagName) !== -1) {
336+
if (lastTagName && this.options.unpairedTagsSet.has(lastTagName)) {
337337
// Pop the unpaired tag
338338
this.matcher.pop();
339339
this.tagsNodeStack.pop();
@@ -438,7 +438,7 @@ const parseXml = function (xmlData) {
438438

439439
//check if last tag was unpaired tag
440440
const lastTag = currentNode;
441-
if (lastTag && this.options.unpairedTags.indexOf(lastTag.tagname) !== -1) {
441+
if (lastTag && this.options.unpairedTagsSet.has(lastTag.tagname)) {
442442
currentNode = this.tagsNodeStack.pop();
443443
this.matcher.pop();
444444
}
@@ -498,7 +498,7 @@ const parseXml = function (xmlData) {
498498
i = result.closeIndex;
499499
}
500500
//unpaired tag
501-
else if (this.options.unpairedTags.indexOf(tagName) !== -1) {
501+
else if (this.options.unpairedTagsSet.has(tagName)) {
502502
i = result.closeIndex;
503503
}
504504
//normal tag
@@ -536,7 +536,7 @@ const parseXml = function (xmlData) {
536536
this.matcher.pop(); // Pop self-closing tag
537537
this.isCurrentNodeStopNode = false; // Reset flag
538538
}
539-
else if (this.options.unpairedTags.indexOf(tagName) !== -1) {//unpaired tag
539+
else if (this.options.unpairedTagsSet.has(tagName)) {//unpaired tag
540540
const childNode = new xmlNode(tagName);
541541
if (prefixedAttrs) {
542542
childNode[":@"] = prefixedAttrs;

0 commit comments

Comments
 (0)