xml-parser-xo
Advanced tools
Comparing version 4.0.5 to 4.1.0
@@ -114,3 +114,14 @@ "use strict"; | ||
// closing | ||
match(/^<\/\s*[\w-:.\u00C0-\u00FF]+>/); | ||
if (parsingState.options.strictMode) { | ||
const closingTag = `</${node.name}>`; | ||
if (parsingState.xml.startsWith(closingTag)) { | ||
parsingState.xml = parsingState.xml.slice(closingTag.length); | ||
} | ||
else { | ||
throw new ParsingError('Failed to parse XML', `Closing tag not matching "${closingTag}"`); | ||
} | ||
} | ||
else { | ||
match(/^<\/\s*[\w-:.\u00C0-\u00FF]+>/); | ||
} | ||
return { | ||
@@ -122,3 +133,3 @@ excluded, | ||
function doctype() { | ||
const m = match(/^<!DOCTYPE\s+[^>]*>/); | ||
const m = match(/^<!DOCTYPE\s+\S+\s+SYSTEM[^>]*>/) || match(/^<!DOCTYPE\s+\S+\s+PUBLIC[^>]*>/) || match(/^<!DOCTYPE\s+\S+\s+\[[^\]]*]>/); | ||
if (m) { | ||
@@ -220,3 +231,3 @@ const node = { | ||
xml, | ||
options: Object.assign(Object.assign({}, options), { filter }) | ||
options: Object.assign(Object.assign({}, options), { filter, strictMode: options.strictMode === true }) | ||
}; | ||
@@ -223,0 +234,0 @@ return parseDocument(); |
@@ -110,3 +110,14 @@ export class ParsingError extends Error { | ||
// closing | ||
match(/^<\/\s*[\w-:.\u00C0-\u00FF]+>/); | ||
if (parsingState.options.strictMode) { | ||
const closingTag = `</${node.name}>`; | ||
if (parsingState.xml.startsWith(closingTag)) { | ||
parsingState.xml = parsingState.xml.slice(closingTag.length); | ||
} | ||
else { | ||
throw new ParsingError('Failed to parse XML', `Closing tag not matching "${closingTag}"`); | ||
} | ||
} | ||
else { | ||
match(/^<\/\s*[\w-:.\u00C0-\u00FF]+>/); | ||
} | ||
return { | ||
@@ -118,3 +129,3 @@ excluded, | ||
function doctype() { | ||
const m = match(/^<!DOCTYPE\s+[^>]*>/); | ||
const m = match(/^<!DOCTYPE\s+\S+\s+SYSTEM[^>]*>/) || match(/^<!DOCTYPE\s+\S+\s+PUBLIC[^>]*>/) || match(/^<!DOCTYPE\s+\S+\s+\[[^\]]*]>/); | ||
if (m) { | ||
@@ -216,3 +227,3 @@ const node = { | ||
xml, | ||
options: Object.assign(Object.assign({}, options), { filter }) | ||
options: Object.assign(Object.assign({}, options), { filter, strictMode: options.strictMode === true }) | ||
}; | ||
@@ -219,0 +230,0 @@ return parseDocument(); |
@@ -6,2 +6,6 @@ export declare type XmlParserOptions = { | ||
filter?: (node: XmlParserNode) => boolean | any; | ||
/** | ||
* True to throw an error when parsing XML document with invalid content like mismatched closing tags. | ||
*/ | ||
strictMode?: boolean; | ||
}; | ||
@@ -8,0 +12,0 @@ export declare type XmlParserNodeType = 'Comment' | 'Text' | 'ProcessingInstruction' | 'Element' | 'DocumentType' | 'CDATA'; |
{ | ||
"name": "xml-parser-xo", | ||
"version": "4.0.5", | ||
"version": "4.1.0", | ||
"repository": "github:chrisbottin/xml-parser", | ||
@@ -5,0 +5,0 @@ "bugs": { |
@@ -66,3 +66,8 @@ | ||
- `filter` (`function(node) => boolean`) Function to filter out unwanted nodes by returning `false`. | ||
- `filter`: Function to filter out unwanted nodes by returning `false`. | ||
- type: `function(node) => boolean` | ||
- default: `() => true` | ||
- `strictMode`: True to throw an error when parsing XML document with invalid content like mismatched closing tags. | ||
- type: `boolean` | ||
- default: `false` | ||
@@ -69,0 +74,0 @@ ### Usage: |
@@ -6,2 +6,6 @@ export type XmlParserOptions = { | ||
filter?: (node: XmlParserNode) => boolean|any; | ||
/** | ||
* True to throw an error when parsing XML document with invalid content like mismatched closing tags. | ||
*/ | ||
strictMode?: boolean; | ||
}; | ||
@@ -202,3 +206,12 @@ | ||
// closing | ||
match(/^<\/\s*[\w-:.\u00C0-\u00FF]+>/); | ||
if (parsingState.options.strictMode) { | ||
const closingTag = `</${node.name}>`; | ||
if (parsingState.xml.startsWith(closingTag)) { | ||
parsingState.xml = parsingState.xml.slice(closingTag.length); | ||
} else { | ||
throw new ParsingError('Failed to parse XML', `Closing tag not matching "${closingTag}"`); | ||
} | ||
} else { | ||
match(/^<\/\s*[\w-:.\u00C0-\u00FF]+>/); | ||
} | ||
@@ -212,3 +225,3 @@ return { | ||
function doctype(): XmlParserNodeWrapper<XmlParserDocumentTypeNode>|undefined { | ||
const m = match(/^<!DOCTYPE\s+[^>]*>/); | ||
const m = match(/^<!DOCTYPE\s+\S+\s+SYSTEM[^>]*>/) || match(/^<!DOCTYPE\s+\S+\s+PUBLIC[^>]*>/) || match(/^<!DOCTYPE\s+\S+\s+\[[^\]]*]>/); | ||
if (m) { | ||
@@ -324,3 +337,4 @@ const node: XmlParserDocumentTypeNode = { | ||
...options, | ||
filter | ||
filter, | ||
strictMode: options.strictMode === true | ||
} | ||
@@ -327,0 +341,0 @@ }; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
42672
823
123