Skip to content

Commit

Permalink
Don't treat XML declarations as Processing Instructions
Browse files Browse the repository at this point in the history
The XML declaration is not a processing instruction.

According to XML 1.0 (5th Edition), Section 2.6, the PI target names "xml",
"XML" and so on are reserved.

Production Rule 17 states:
> PITarget ::= Name - (('X' | 'x') ('M' | 'm') ('L' | 'l'))

This fixes #174.
  • Loading branch information
Holzhaus committed Jun 11, 2017
1 parent e0e40f6 commit a359ead
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions sax.js
Original file line number Diff line number Diff line change
Expand Up @@ -549,10 +549,11 @@ function parseDCC(source,start,domBuilder,errorHandler){//sure start with '<!'
function parseInstruction(source,start,domBuilder){
var end = source.indexOf('?>',start);
if(end){
var match = source.substring(start,end).match(/^<\?(\S*)\s*([\s\S]*?)\s*$/);
var match = source.substring(start,end).match(/^<\?(\S+)\s*([\s\S]*?)\s*$/);
if(match){
var len = match[0].length;
domBuilder.processingInstruction(match[1], match[2]) ;
if(match[1].toLowerCase() !== 'xml'){//ignore XML declarations
domBuilder.processingInstruction(match[1], match[2]) ;
}
return end+2;
}else{//error
return -1;
Expand Down

0 comments on commit a359ead

Please sign in to comment.