@file-type/xml
Advanced tools
Comparing version 0.2.0 to 0.2.1
@@ -86,14 +86,18 @@ | ||
constructor() { | ||
constructor(options) { | ||
this.options = options ?? {}; | ||
this.firstTag = true; | ||
this.onEnd = false; | ||
this.parser = sax.parser(true); | ||
this.depth = 0; | ||
this.validClose = false; | ||
this.nesting = 0; | ||
this.parser.onerror = e => { | ||
if (e.message.startsWith('Invalid character entity')) { // Allow entity reference | ||
return; | ||
} | ||
this.fileType = undefined; | ||
this.onEnd = true; | ||
}; | ||
this.parser.onopentag = node => { | ||
++this.depth; | ||
++this.nesting; | ||
if (!this.firstTag || this.onEnd) { | ||
@@ -112,9 +116,10 @@ return; | ||
if (this.fileType) { | ||
if (this.fileType && !this.options.fullScan) { | ||
this.onEnd = true; | ||
} | ||
}; | ||
this.parser.onend = () => { | ||
this.onEnd = true; | ||
}; | ||
this.parser.onclosetag = () => { | ||
--this.nesting; | ||
} | ||
} | ||
@@ -130,2 +135,6 @@ | ||
} | ||
isValid() { | ||
return this.nesting === 0; | ||
} | ||
} | ||
@@ -144,3 +153,2 @@ | ||
await tokenizer.ignore(offset); | ||
let fileType; | ||
@@ -147,0 +155,0 @@ const xmlTextDetector = new XmlTextDetector(); |
{ | ||
"name": "@file-type/xml", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "XML detection plugin", | ||
@@ -5,0 +5,0 @@ "type": "module", |
6935
147