File tree Expand file tree Collapse file tree 2 files changed +22
-8
lines changed Expand file tree Collapse file tree 2 files changed +22
-8
lines changed Original file line number Diff line number Diff line change @@ -272,6 +272,16 @@ describe("XMLParser", function () {
272
272
'<h1></h1>' +
273
273
'<?mso-contentType something="val"?>' ) ;
274
274
} ) ;
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
+ } ) ;
275
285
276
286
it ( "should not validate XML PIs with invalid values" , function ( ) {
277
287
validate ( '<?xml version="1.0"?>' +
Original file line number Diff line number Diff line change @@ -27,17 +27,18 @@ exports.validate = function (xmlData, options) {
27
27
}
28
28
29
29
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 ] === '<' ) {
31
36
//starting of tag
32
37
//read until you reach to '>' avoiding any '>' in attribute value
33
38
34
39
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 ] === '!' ) {
41
42
i = readCommentAndCDATA ( xmlData , i ) ;
42
43
continue ;
43
44
} else {
@@ -140,7 +141,10 @@ exports.validate = function (xmlData, options) {
140
141
i ++ ;
141
142
i = readCommentAndCDATA ( xmlData , i ) ;
142
143
continue ;
143
- } else {
144
+ } else if ( xmlData [ i + 1 ] === '?' ) {
145
+ i = readPI ( xmlData , ++ i ) ;
146
+ if ( i . err ) return i ;
147
+ } else {
144
148
break ;
145
149
}
146
150
} else if ( xmlData [ i ] === '&' ) {
You can’t perform that action at this time.
0 commit comments