fast-xml-parser
Advanced tools
Comparing version 4.1.2 to 4.1.3
Note: If you find missing information about particular minor version, that version must have been changed without any functional change in this library. | ||
**4.1.3 / 2023-02-26** | ||
* fix #546: Support complex entity value | ||
**4.1.2 / 2023-02-12** | ||
* Security Fix | ||
**4.1.1 / 2023-02-03** | ||
@@ -4,0 +10,0 @@ * Fix #540: ignoreAttributes breaks unpairedTags |
{ | ||
"name": "fast-xml-parser", | ||
"version": "4.1.2", | ||
"version": "4.1.3", | ||
"description": "Validate XML, Parse XML, Build XML without C/C++ based libraries", | ||
@@ -56,3 +56,3 @@ "main": "./src/fxp.js", | ||
"prettier": "^1.19.1", | ||
"publish-please": "^2.4.1", | ||
"publish-please": "^5.5.2", | ||
"webpack": "^5.64.4", | ||
@@ -59,0 +59,0 @@ "webpack-cli": "^4.9.1" |
@@ -14,66 +14,24 @@ //TODO: handle comments | ||
let angleBracketsCount = 1; | ||
let hasBody = false, entity = false, comment = false; | ||
let hasBody = false, comment = false; | ||
let exp = ""; | ||
for(;i<xmlData.length;i++){ | ||
if (xmlData[i] === '<' && !comment) { | ||
if( hasBody && | ||
xmlData[i+1] === '!' && | ||
xmlData[i+2] === 'E' && | ||
xmlData[i+3] === 'N' && | ||
xmlData[i+4] === 'T' && | ||
xmlData[i+5] === 'I' && | ||
xmlData[i+6] === 'T' && | ||
xmlData[i+7] === 'Y' | ||
){ | ||
i += 7; | ||
entity = true; | ||
}else if( hasBody && | ||
xmlData[i+1] === '!' && | ||
xmlData[i+2] === 'E' && | ||
xmlData[i+3] === 'L' && | ||
xmlData[i+4] === 'E' && | ||
xmlData[i+5] === 'M' && | ||
xmlData[i+6] === 'E' && | ||
xmlData[i+7] === 'N' && | ||
xmlData[i+8] === 'T' | ||
){ | ||
//Not supported | ||
i += 8; | ||
}else if( hasBody && | ||
xmlData[i+1] === '!' && | ||
xmlData[i+2] === 'A' && | ||
xmlData[i+3] === 'T' && | ||
xmlData[i+4] === 'T' && | ||
xmlData[i+5] === 'L' && | ||
xmlData[i+6] === 'I' && | ||
xmlData[i+7] === 'S' && | ||
xmlData[i+8] === 'T' | ||
){ | ||
//Not supported | ||
i += 8; | ||
}else if( hasBody && | ||
xmlData[i+1] === '!' && | ||
xmlData[i+2] === 'N' && | ||
xmlData[i+3] === 'O' && | ||
xmlData[i+4] === 'T' && | ||
xmlData[i+5] === 'A' && | ||
xmlData[i+6] === 'T' && | ||
xmlData[i+7] === 'I' && | ||
xmlData[i+8] === 'O' && | ||
xmlData[i+9] === 'N' | ||
){ | ||
//Not supported | ||
i += 9; | ||
}else if( //comment | ||
xmlData[i+1] === '!' && | ||
xmlData[i+2] === '-' && | ||
xmlData[i+3] === '-' | ||
){ | ||
comment = true; | ||
}else{ | ||
throw new Error("Invalid DOCTYPE"); | ||
if (xmlData[i] === '<' && !comment) { //Determine the tag type | ||
if( hasBody && isEntity(xmlData, i)){ | ||
i += 7; | ||
[entityName, val,i] = readEntityExp(xmlData,i+1); | ||
if(val.indexOf("&") === -1) //Parameter entities are not supported | ||
entities[ entityName ] = { | ||
regx : RegExp( `&${entityName};`,"g"), | ||
val: val | ||
}; | ||
} | ||
else if( hasBody && isElement(xmlData, i)) i += 8;//Not supported | ||
else if( hasBody && isAttlist(xmlData, i)) i += 8;//Not supported | ||
else if( hasBody && isNotation(xmlData, i)) i += 9;//Not supported | ||
else if( isComment) comment = true; | ||
else throw new Error("Invalid DOCTYPE"); | ||
angleBracketsCount++; | ||
exp = ""; | ||
} else if (xmlData[i] === '>') { | ||
} else if (xmlData[i] === '>') { //Read tag content | ||
if(comment){ | ||
@@ -85,6 +43,2 @@ if( xmlData[i - 1] === "-" && xmlData[i - 2] === "-"){ | ||
}else{ | ||
if(entity) { | ||
parseEntityExp(exp, entities); | ||
entity = false; | ||
} | ||
angleBracketsCount--; | ||
@@ -110,12 +64,83 @@ } | ||
const entityRegex = RegExp("^\\s([a-zA-z0-0]+)[ \t](['\"])([^&]+)\\2"); | ||
function parseEntityExp(exp, entities){ | ||
const match = entityRegex.exec(exp); | ||
if(match){ | ||
entities[ match[1] ] = { | ||
regx : RegExp( `&${match[1]};`,"g"), | ||
val: match[3] | ||
}; | ||
function readEntityExp(xmlData,i){ | ||
//External entities are not supported | ||
// <!ENTITY ext SYSTEM "http://normal-website.com" > | ||
//Parameter entities are not supported | ||
// <!ENTITY entityname "&anotherElement;"> | ||
//Internal entities are supported | ||
// <!ENTITY entityname "replacement text"> | ||
//read EntityName | ||
let entityName = ""; | ||
for (; i < xmlData.length && (xmlData[i] !== "'" && xmlData[i] !== '"' ); i++) { | ||
// if(xmlData[i] === " ") continue; | ||
// else | ||
entityName += xmlData[i]; | ||
} | ||
entityName = entityName.trim(); | ||
if(entityName.indexOf(" ") !== -1) throw new Error("External entites are not supported"); | ||
//read Entity Value | ||
const startChar = xmlData[i++]; | ||
let val = "" | ||
for (; i < xmlData.length && xmlData[i] !== startChar ; i++) { | ||
val += xmlData[i]; | ||
} | ||
return [entityName, val, i]; | ||
} | ||
function isComment(xmlData, i){ | ||
if(xmlData[i+1] === '!' && | ||
xmlData[i+2] === '-' && | ||
xmlData[i+3] === '-') return true | ||
return false | ||
} | ||
function isEntity(xmlData, i){ | ||
if(xmlData[i+1] === '!' && | ||
xmlData[i+2] === 'E' && | ||
xmlData[i+3] === 'N' && | ||
xmlData[i+4] === 'T' && | ||
xmlData[i+5] === 'I' && | ||
xmlData[i+6] === 'T' && | ||
xmlData[i+7] === 'Y') return true | ||
return false | ||
} | ||
function isElement(xmlData, i){ | ||
if(xmlData[i+1] === '!' && | ||
xmlData[i+2] === 'E' && | ||
xmlData[i+3] === 'L' && | ||
xmlData[i+4] === 'E' && | ||
xmlData[i+5] === 'M' && | ||
xmlData[i+6] === 'E' && | ||
xmlData[i+7] === 'N' && | ||
xmlData[i+8] === 'T') return true | ||
return false | ||
} | ||
function isAttlist(xmlData, i){ | ||
if(xmlData[i+1] === '!' && | ||
xmlData[i+2] === 'A' && | ||
xmlData[i+3] === 'T' && | ||
xmlData[i+4] === 'T' && | ||
xmlData[i+5] === 'L' && | ||
xmlData[i+6] === 'I' && | ||
xmlData[i+7] === 'S' && | ||
xmlData[i+8] === 'T') return true | ||
return false | ||
} | ||
function isNotation(xmlData, i){ | ||
if(xmlData[i+1] === '!' && | ||
xmlData[i+2] === 'N' && | ||
xmlData[i+3] === 'O' && | ||
xmlData[i+4] === 'T' && | ||
xmlData[i+5] === 'A' && | ||
xmlData[i+6] === 'T' && | ||
xmlData[i+7] === 'I' && | ||
xmlData[i+8] === 'O' && | ||
xmlData[i+9] === 'N') return true | ||
return false | ||
} | ||
module.exports = readDocType; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
101076
1909