@oozcitak/dom
Advanced tools
Comparing version 1.15.3 to 1.15.4
@@ -22,5 +22,6 @@ "use strict"; | ||
catch (e) { | ||
const errorNS = "http://www.mozilla.org/newlayout/xml/parsererror.xml"; | ||
const doc = algorithm_1.create_xmlDocument(); | ||
const root = doc.createElementNS("http://www.mozilla.org/newlayout/xml/parsererror.xml", "parsererror"); | ||
const ele = doc.createElement("error"); | ||
const root = doc.createElementNS(errorNS, "parsererror"); | ||
const ele = doc.createElementNS(errorNS, "error"); | ||
ele.setAttribute("message", e.message); | ||
@@ -27,0 +28,0 @@ root.appendChild(ele); |
@@ -89,2 +89,4 @@ "use strict"; | ||
// attribute | ||
// also lookup namespace declaration attributes | ||
const nsDeclarations = {}; | ||
for (const [attName, attValue] of element.attributes) { | ||
@@ -96,4 +98,7 @@ if (attName === "xmlns") { | ||
const [attPrefix, attLocalName] = algorithm_1.namespace_extractQName(attName); | ||
if (attPrefix === "xmlns" && attLocalName === prefix) { | ||
namespace = attValue; | ||
if (attPrefix === "xmlns") { | ||
if (attLocalName === prefix) { | ||
namespace = attValue; | ||
} | ||
nsDeclarations[attLocalName] = attValue; | ||
} | ||
@@ -110,10 +115,6 @@ } | ||
for (const [attName, attValue] of element.attributes) { | ||
// skip the default namespace declaration attribute | ||
if (attName === "xmlns") { | ||
continue; | ||
} | ||
const [attPrefix, attLocalName] = algorithm_1.namespace_extractQName(attName); | ||
let attNamespace = null; | ||
if (attPrefix === "xmlns") { | ||
// prefixed namespace declaration attribute | ||
if (attPrefix === "xmlns" || (attPrefix === null && attLocalName === "xmlns")) { | ||
// namespace declaration attribute | ||
attNamespace = infra_1.namespace.XMLNS; | ||
@@ -126,2 +127,5 @@ } | ||
} | ||
else if (attNamespace === null && attPrefix !== null) { | ||
attNamespace = nsDeclarations[attPrefix] || null; | ||
} | ||
} | ||
@@ -136,10 +140,9 @@ if (localNameSet.has(attNamespace, attLocalName)) { | ||
} | ||
if (attValue === "") { | ||
throw new Error("Namespace prefix declarations cannot be used to undeclare a namespace."); | ||
} | ||
} | ||
if (attLocalName.indexOf(":") !== -1 || !algorithm_1.xml_isName(attLocalName) || | ||
(attLocalName === "xmlns" && attNamespace === null)) { | ||
if (attLocalName.indexOf(":") !== -1 || !algorithm_1.xml_isName(attLocalName)) { | ||
throw new Error("Attribute local name contains invalid characters."); | ||
} | ||
if (attPrefix === "xmlns" && attValue === "") { | ||
throw new Error("Empty XML namespace is not allowed."); | ||
} | ||
if (attNamespace !== null) | ||
@@ -146,0 +149,0 @@ elementNode.setAttributeNS(attNamespace, attName, attValue); |
@@ -10,2 +10,8 @@ import { XMLToken, XMLLexer, XMLLexerOptions } from "./interfaces"; | ||
private _options; | ||
err: { | ||
line: number; | ||
col: number; | ||
index: number; | ||
str: string; | ||
}; | ||
/** | ||
@@ -144,2 +150,9 @@ * Initializes a new instance of `XMLStringLexer`. | ||
/** | ||
* Throws a parser error and records the line and column numbers in the parsed | ||
* string. | ||
* | ||
* @param msg - error message | ||
*/ | ||
private throwError; | ||
/** | ||
* Returns an iterator for the lexer. | ||
@@ -146,0 +159,0 @@ */ |
@@ -18,2 +18,3 @@ "use strict"; | ||
}; | ||
this.err = { line: -1, col: -1, index: -1, str: "" }; | ||
this._str = str; | ||
@@ -72,3 +73,3 @@ this._index = 0; | ||
else { | ||
throw new Error("Invalid '!' in opening tag."); | ||
this.throwError("Invalid '!' in opening tag."); | ||
} | ||
@@ -105,6 +106,6 @@ } | ||
else | ||
throw new Error('Invalid attribute name: ' + attName); | ||
this.throwError('Invalid attribute name: ' + attName); | ||
} | ||
} | ||
throw new Error('Missing declaration end symbol `?>`'); | ||
this.throwError('Missing declaration end symbol `?>`'); | ||
} | ||
@@ -134,3 +135,3 @@ /** | ||
if (!this.skipIfStartsWith(']')) { | ||
throw new Error('Missing end bracket of DTD internal subset'); | ||
this.throwError('Missing end bracket of DTD internal subset'); | ||
} | ||
@@ -140,3 +141,3 @@ } | ||
if (!this.skipIfStartsWith('>')) { | ||
throw new Error('Missing doctype end symbol `>`'); | ||
this.throwError('Missing doctype end symbol `>`'); | ||
} | ||
@@ -151,3 +152,3 @@ return { type: interfaces_1.TokenType.DocType, name: name, pubId: pubId, sysId: sysId }; | ||
if (this.eof()) { | ||
throw new Error('Missing processing instruction end symbol `?>`'); | ||
this.throwError('Missing processing instruction end symbol `?>`'); | ||
} | ||
@@ -160,3 +161,3 @@ this.skipSpace(); | ||
if (this.eof()) { | ||
throw new Error('Missing processing instruction end symbol `?>`'); | ||
this.throwError('Missing processing instruction end symbol `?>`'); | ||
} | ||
@@ -181,3 +182,3 @@ this.seek(2); | ||
if (this.eof()) { | ||
throw new Error('Missing comment end symbol `-->`'); | ||
this.throwError('Missing comment end symbol `-->`'); | ||
} | ||
@@ -194,3 +195,3 @@ this.seek(3); | ||
if (this.eof()) { | ||
throw new Error('Missing CDATA end symbol `]>`'); | ||
this.throwError('Missing CDATA end symbol `]>`'); | ||
} | ||
@@ -228,3 +229,3 @@ this.seek(3); | ||
} | ||
throw new Error('Missing opening element tag end symbol `>`'); | ||
this.throwError('Missing opening element tag end symbol `>`'); | ||
} | ||
@@ -240,3 +241,3 @@ /** | ||
if (!this.skipIfStartsWith('>')) { | ||
throw new Error('Missing closing element tag end symbol `>`'); | ||
this.throwError('Missing closing element tag end symbol `>`'); | ||
} | ||
@@ -254,3 +255,3 @@ return { type: interfaces_1.TokenType.ClosingTag, name: name }; | ||
if (!this.skipIfStartsWith('=')) { | ||
throw new Error('Missing equals sign before attribute value'); | ||
this.throwError('Missing equals sign before attribute value'); | ||
} | ||
@@ -268,7 +269,7 @@ // attribute value | ||
if (!XMLStringLexer.isQuote(startQuote)) { | ||
throw new Error('Missing start quote character before quoted value'); | ||
this.throwError('Missing start quote character before quoted value'); | ||
} | ||
const value = this.takeUntil(startQuote); | ||
if (!this.skipIfStartsWith(startQuote)) { | ||
throw new Error('Missing end quote character after quoted value'); | ||
this.throwError('Missing end quote character after quoted value'); | ||
} | ||
@@ -453,2 +454,35 @@ return value; | ||
/** | ||
* Throws a parser error and records the line and column numbers in the parsed | ||
* string. | ||
* | ||
* @param msg - error message | ||
*/ | ||
throwError(msg) { | ||
const regexp = /\r\n|\r|\n/g; | ||
let match = null; | ||
let line = 0; | ||
let firstNewLineIndex = 0; | ||
let lastNewlineIndex = this._str.length; | ||
while ((match = regexp.exec(this._str)) !== null) { | ||
if (match === null) | ||
break; | ||
line++; | ||
if (match.index < this._index) | ||
firstNewLineIndex = regexp.lastIndex; | ||
if (match.index > this._index) { | ||
lastNewlineIndex = match.index; | ||
break; | ||
} | ||
} | ||
this.err = { | ||
line: line, | ||
col: this._index - firstNewLineIndex, | ||
index: this._index, | ||
str: this._str.substring(firstNewLineIndex, lastNewlineIndex) | ||
}; | ||
throw new Error(msg + "\nIndex: " + this.err.index + | ||
"\nLn: " + this.err.line + ", Col: " + this.err.col + | ||
"\nInput: " + this.err.str); | ||
} | ||
/** | ||
* Returns an iterator for the lexer. | ||
@@ -455,0 +489,0 @@ */ |
{ | ||
"name": "@oozcitak/dom", | ||
"version": "1.15.3", | ||
"version": "1.15.4", | ||
"keywords": [ | ||
@@ -5,0 +5,0 @@ "dom", |
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
Sorry, the diff of this file is too big to display
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
1107088
21897