Skip to content

Commit ec25c54

Browse files
committed
fix #317 : validate nested PI tags
1 parent eb8b6c5 commit ec25c54

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

spec/validator_spec.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,16 @@ describe("XMLParser", function () {
272272
'<h1></h1>' +
273273
'<?mso-contentType something="val"?>');
274274
});
275+
276+
it("should validate XML PIs", function () {
277+
validate('<h1><?mso?> abc</h1>');
278+
});
279+
280+
it("should validate XML PIs", function () {
281+
const xml = `<?xml version="1.0"?>
282+
<content><?tibcochar ?> something</content>`;
283+
validate(xml);
284+
});
275285

276286
it("should not validate XML PIs with invalid values", function () {
277287
validate('<?xml version="1.0"?>' +

src/validator.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,18 @@ exports.validate = function (xmlData, options) {
2727
}
2828

2929
for (let i = 0; i < xmlData.length; i++) {
30-
if (xmlData[i] === '<') {
30+
31+
if (xmlData[i] === '<' && xmlData[i+1] === '?') {
32+
i+=2;
33+
i = readPI(xmlData,i);
34+
if (i.err) return i;
35+
}else if (xmlData[i] === '<') {
3136
//starting of tag
3237
//read until you reach to '>' avoiding any '>' in attribute value
3338

3439
i++;
35-
if (xmlData[i] === '?') {
36-
i = readPI(xmlData, ++i);
37-
if (i.err) {
38-
return i;
39-
}
40-
} else if (xmlData[i] === '!') {
40+
41+
if (xmlData[i] === '!') {
4142
i = readCommentAndCDATA(xmlData, i);
4243
continue;
4344
} else {
@@ -140,7 +141,10 @@ exports.validate = function (xmlData, options) {
140141
i++;
141142
i = readCommentAndCDATA(xmlData, i);
142143
continue;
143-
} else {
144+
} else if (xmlData[i+1] === '?') {
145+
i = readPI(xmlData, ++i);
146+
if (i.err) return i;
147+
} else{
144148
break;
145149
}
146150
} else if (xmlData[i] === '&') {

0 commit comments

Comments
 (0)