Skip to content

Commit 201a424

Browse files
committed
fix space after tagname causing issue
1 parent 626c432 commit 201a424

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

spec/data_spec.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,5 +258,19 @@ describe("XMLParser", function() {
258258
}).toThrowError("Pi Tag is not closed.")
259259
})
260260

261+
it("should parse XML when there is a space after tagname", function() {
262+
const xmlData = `<tag ><![CDATA[undefined]]><nested>undefined</nested></tag>`;
263+
const expected = {
264+
"tag" : {
265+
"#text": "undefined",
266+
"nested": "undefined"
267+
}
268+
};
261269

270+
const result = parser.parse(xmlData, {
271+
ignoreAttributes: false,
272+
allowBooleanAttributes: true
273+
},true);
274+
expect(result).toEqual(expected);
275+
});
262276
});

src/xmlstr2xmlnode.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ const getTraversalObj = function(xmlData, options) {
272272
}
273273
}
274274

275-
if(tagExp.lastIndexOf("/") === tagExp.length - 1){//selfClosing tag
275+
if(tagExp.length > 0 && tagExp.lastIndexOf("/") === tagExp.length - 1){//selfClosing tag
276276

277277
if(tagName[tagName.length - 1] === "/"){ //remove trailing '/'
278278
tagName = tagName.substr(0, tagName.length - 1);

0 commit comments

Comments
 (0)