Socket
Socket
Sign inDemoInstall

@oozcitak/dom

Package Overview
Dependencies
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@oozcitak/dom - npm Package Compare versions

Comparing version 1.9.0 to 1.10.0

lib/parser/XMLParserImpl.d.ts

2

lib/algorithm/MutationAlgorithm.js

@@ -41,3 +41,3 @@ "use strict";

if (TreeAlgorithm_1.tree_isHostIncludingAncestorOf(parent, node, true))
throw new DOMException_1.HierarchyRequestError(`The node to be inserted cannot be an ancestor of parent node. Node is ${node.nodeName}, parent node is ${parent.nodeName}.`);
throw new DOMException_1.HierarchyRequestError(`The node to be inserted cannot be an inclusive ancestor of parent node. Node is ${node.nodeName}, parent node is ${parent.nodeName}.`);
/**

@@ -44,0 +44,0 @@ * 3. If child is not null and its parent is not parent, then throw a

@@ -524,9 +524,11 @@ "use strict";

function tree_isAncestorOf(node, other, self = false, shadow = false) {
/**
* An object A is called an ancestor of an object B if and only if B is a
* descendant of A.
*
* An inclusive ancestor is an object or one of its ancestors.
*/
return tree_isDescendantOf(other, node, self, shadow);
let ancestor = self ? node : shadow && util_1.Guard.isShadowRoot(node) ?
node._host : node._parent;
while (ancestor !== null) {
if (ancestor === other)
return true;
ancestor = shadow && util_1.Guard.isShadowRoot(ancestor) ?
ancestor._host : ancestor._parent;
}
return false;
}

@@ -549,3 +551,3 @@ exports.tree_isAncestorOf = tree_isAncestorOf;

if (util_1.Guard.isDocumentFragmentNode(root) && root._host !== null &&
tree_isAncestorOf(root._host, other, true))
tree_isHostIncludingAncestorOf(root._host, other, self))
return true;

@@ -552,0 +554,0 @@ return false;

@@ -17,5 +17,4 @@ /**

* @param chars - sequence of characters to test
* @param xmlVersion - XML specification version
*/
export declare function xml_isLegalChar(chars: string, xmlVersion?: "1.0" | "1.1"): boolean;
export declare function xml_isLegalChar(chars: string): boolean;
/**

@@ -22,0 +21,0 @@ * Determines if the given string contains legal characters for a public

@@ -10,11 +10,3 @@ "use strict";

for (let i = 0; i < name.length; i++) {
const c1 = name.charCodeAt(i);
let n = c1;
if (c1 >= 0xD800 && c1 <= 0xDBFF && i < name.length - 1) {
const c2 = name.charCodeAt(i + 1);
if (c2 >= 0xDC00 && c2 <= 0xDFFF) {
n = (c1 - 0xD800) * 0x400 + c2 - 0xDC00 + 0x10000;
i++;
}
}
let n = name.charCodeAt(i);
// NameStartChar

@@ -34,19 +26,24 @@ if ((n >= 97 && n <= 122) || // [a-z]

(n >= 0xF900 && n <= 0xFDCF) ||
(n >= 0xFDF0 && n <= 0xFFFD) ||
(n >= 0x10000 && n <= 0xEFFFF)) {
(n >= 0xFDF0 && n <= 0xFFFD)) {
continue;
}
else if (i === 0) {
return false;
}
else if (n === 45 || n === 46 || // '-' or '.'
(n >= 48 && n <= 57) || // [0-9]
(n === 0xB7) ||
(n >= 0x0300 && n <= 0x036F) ||
(n >= 0x203F && n <= 0x2040)) {
else if (i !== 0 &&
(n === 45 || n === 46 || // '-' or '.'
(n >= 48 && n <= 57) || // [0-9]
(n === 0xB7) ||
(n >= 0x0300 && n <= 0x036F) ||
(n >= 0x203F && n <= 0x2040))) {
continue;
}
else {
return false;
if (n >= 0xD800 && n <= 0xDBFF && i < name.length - 1) {
const n2 = name.charCodeAt(i + 1);
if (n2 >= 0xDC00 && n2 <= 0xDFFF) {
n = (n - 0xD800) * 0x400 + n2 - 0xDC00 + 0x10000;
i++;
if (n >= 0x10000 && n <= 0xEFFFF) {
continue;
}
}
}
return false;
}

@@ -64,15 +61,7 @@ return true;

for (let i = 0; i < name.length; i++) {
const c1 = name.charCodeAt(i);
let n = c1;
if (c1 >= 0xD800 && c1 <= 0xDBFF && i < name.length - 1) {
const c2 = name.charCodeAt(i + 1);
if (c2 >= 0xDC00 && c2 <= 0xDFFF) {
n = (c1 - 0xD800) * 0x400 + c2 - 0xDC00 + 0x10000;
i++;
}
}
let n = name.charCodeAt(i);
// NameStartChar
if ((n >= 97 && n <= 122) || // [a-z]
(n >= 65 && n <= 90) || // [A-Z]
n === 95 || // or '_'
n === 95 || // '_'
(n >= 0xC0 && n <= 0xD6) ||

@@ -88,10 +77,14 @@ (n >= 0xD8 && n <= 0xF6) ||

(n >= 0xF900 && n <= 0xFDCF) ||
(n >= 0xFDF0 && n <= 0xFFFD) ||
(n >= 0x10000 && n <= 0xEFFFF)) {
(n >= 0xFDF0 && n <= 0xFFFD)) {
continue;
}
else if (i === 0) {
return false;
else if (i !== 0 &&
(n === 45 || n === 46 || // '-' or '.'
(n >= 48 && n <= 57) || // [0-9]
(n === 0xB7) ||
(n >= 0x0300 && n <= 0x036F) ||
(n >= 0x203F && n <= 0x2040))) {
continue;
}
else if (n === 58) { // ':'
else if (i !== 0 && n === 58) { // :
if (colonFound)

@@ -104,12 +97,13 @@ return false; // multiple colons in qname

}
else if (n === 45 || n === 46 || // '-' or '.'
(n >= 48 && n <= 57) || // [0-9]
(n === 0xB7) ||
(n >= 0x0300 && n <= 0x036F) ||
(n >= 0x203F && n <= 0x2040)) {
continue;
if (n >= 0xD800 && n <= 0xDBFF && i < name.length - 1) {
const n2 = name.charCodeAt(i + 1);
if (n2 >= 0xDC00 && n2 <= 0xDFFF) {
n = (n - 0xD800) * 0x400 + n2 - 0xDC00 + 0x10000;
i++;
if (n >= 0x10000 && n <= 0xEFFFF) {
continue;
}
}
}
else {
return false;
}
return false;
}

@@ -123,38 +117,23 @@ return true;

* @param chars - sequence of characters to test
* @param xmlVersion - XML specification version
*/
function xml_isLegalChar(chars, xmlVersion = "1.0") {
function xml_isLegalChar(chars) {
for (let i = 0; i < chars.length; i++) {
const c1 = chars.charCodeAt(i);
let n = c1;
if (c1 >= 0xD800 && c1 <= 0xDBFF && i < chars.length - 1) {
const c2 = chars.charCodeAt(i + 1);
if (c2 >= 0xDC00 && c2 <= 0xDFFF) {
n = (c1 - 0xD800) * 0x400 + c2 - 0xDC00 + 0x10000;
let n = chars.charCodeAt(i);
// #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
if (n === 0x9 || n === 0xA || n === 0xD ||
(n >= 0x20 && n <= 0xD7FF) ||
(n >= 0xE000 && n <= 0xFFFD)) {
continue;
}
if (n >= 0xD800 && n <= 0xDBFF && i < chars.length - 1) {
const n2 = chars.charCodeAt(i + 1);
if (n2 >= 0xDC00 && n2 <= 0xDFFF) {
n = (n - 0xD800) * 0x400 + n2 - 0xDC00 + 0x10000;
i++;
if (n >= 0x10000 && n <= 0x10FFFF) {
continue;
}
}
}
if (xmlVersion === "1.0") {
// #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
if (n === 0x9 || n === 0xA || n === 0xD ||
(n >= 0x20 && n <= 0xD7FF) ||
(n >= 0xE000 && n <= 0xFFFD) ||
(n >= 0x10000 && n <= 0x10FFFF)) {
continue;
}
else {
return false;
}
}
else {
// [#x1-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
if ((n >= 0x1 && n <= 0xD7FF) ||
(n >= 0xE000 && n <= 0xFFFD) ||
(n >= 0x10000 && n <= 0x10FFFF)) {
continue;
}
else {
return false;
}
}
return false;
}

@@ -161,0 +140,0 @@ return true;

@@ -9,11 +9,4 @@ import { DOMParser, MimeType } from "./interfaces";

export declare class DOMParserImpl implements DOMParser {
private _xmlVersion?;
/**
* Initializes a new instance of `XMLSerializer`.
*
* @param xmlVersion - XML specification version
*/
constructor(xmlVersion?: "1.0" | "1.1");
/** @inheritdoc */
parseFromString(source: string, mimeType: MimeType): Document;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const XMLStringLexer_1 = require("./XMLStringLexer");
const interfaces_1 = require("./interfaces");
const infra_1 = require("@oozcitak/infra");
const algorithm_1 = require("../algorithm");
const LocalNameSet_1 = require("../serializer/LocalNameSet");
const XMLParserImpl_1 = require("./XMLParserImpl");
/**

@@ -14,168 +11,21 @@ * Represents a parser for XML and HTML content.

class DOMParserImpl {
/**
* Initializes a new instance of `XMLSerializer`.
*
* @param xmlVersion - XML specification version
*/
constructor(xmlVersion) {
this._xmlVersion = xmlVersion;
}
/** @inheritdoc */
parseFromString(source, mimeType) {
if (mimeType === "text/html") {
if (mimeType === "text/html")
throw new Error('HTML parser not implemented.');
}
else {
const lexer = new XMLStringLexer_1.XMLStringLexer(source, { skipWhitespaceOnlyText: true });
const doc = algorithm_1.create_document();
try {
const parser = new XMLParserImpl_1.XMLParserImpl();
const doc = parser.parse(source);
doc._contentType = mimeType;
let xmlVersion = this._xmlVersion || "1.0";
let context = doc;
let token = lexer.nextToken();
while (token.type !== interfaces_1.TokenType.EOF) {
switch (token.type) {
case interfaces_1.TokenType.Declaration:
if (this._xmlVersion === undefined) {
const declaration = token;
if (declaration.version === "1.0" || declaration.version === "1.1") {
xmlVersion = declaration.version;
}
else if (declaration.version !== "") {
throw new Error("Invalid xml version: " + declaration.version);
}
}
break;
case interfaces_1.TokenType.DocType:
const doctype = token;
if (!algorithm_1.xml_isPubidChar(doctype.pubId)) {
throw new Error("DocType public identifier does not match PubidChar construct.");
}
if (!algorithm_1.xml_isLegalChar(doctype.sysId, xmlVersion) ||
(doctype.sysId.indexOf('"') !== -1 && doctype.sysId.indexOf("'") !== -1)) {
throw new Error("DocType system identifier contains invalid characters.");
}
context.appendChild(doc.implementation.createDocumentType(doctype.name, doctype.pubId, doctype.sysId));
break;
case interfaces_1.TokenType.CDATA:
const cdata = token;
if (!algorithm_1.xml_isLegalChar(cdata.data, xmlVersion) ||
cdata.data.indexOf("]]>") !== -1) {
throw new Error("CDATA contains invalid characters.");
}
context.appendChild(doc.createCDATASection(cdata.data));
break;
case interfaces_1.TokenType.Comment:
const comment = token;
if (!algorithm_1.xml_isLegalChar(comment.data, xmlVersion) ||
comment.data.indexOf("--") !== -1 || comment.data.endsWith("-")) {
throw new Error("Comment data contains invalid characters.");
}
context.appendChild(doc.createComment(comment.data));
break;
case interfaces_1.TokenType.PI:
const pi = token;
if (pi.target.indexOf(":") !== -1 || (/^xml$/i).test(pi.target)) {
throw new Error("Processing instruction target contains invalid characters.");
}
if (!algorithm_1.xml_isLegalChar(pi.data, xmlVersion) || pi.data.indexOf("?>") !== -1) {
throw new Error("Processing instruction data contains invalid characters.");
}
context.appendChild(doc.createProcessingInstruction(pi.target, pi.data));
break;
case interfaces_1.TokenType.Text:
const text = token;
if (!algorithm_1.xml_isLegalChar(text.data, xmlVersion)) {
throw new Error("Text data contains invalid characters.");
}
context.appendChild(doc.createTextNode(text.data));
break;
case interfaces_1.TokenType.Element:
const element = token;
// inherit namespace from parent
const [prefix, localName] = algorithm_1.namespace_extractQName(element.name);
if (localName.indexOf(":") !== -1 || !algorithm_1.xml_isName(localName)) {
throw new Error("Node local name contains invalid characters.");
}
if (prefix === "xmlns") {
throw new Error("An element cannot have the 'xmlns' prefix.");
}
let namespace = context.lookupNamespaceURI(prefix);
// override namespace if there is a namespace declaration
// attribute
for (const attName in element.attributes) {
const attValue = element.attributes[attName];
if (attName === "xmlns") {
namespace = attValue;
}
else {
const [attPrefix, attLocalName] = algorithm_1.namespace_extractQName(attName);
if (attPrefix === "xmlns" && attLocalName === prefix) {
namespace = attValue;
}
}
}
// create the DOM element node
const elementNode = (namespace !== null ?
doc.createElementNS(namespace, element.name) :
doc.createElement(element.name));
context.appendChild(elementNode);
// assign attributes
const localNameSet = new LocalNameSet_1.LocalNameSet();
for (const attName in element.attributes) {
const attValue = element.attributes[attName];
// 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
attNamespace = infra_1.namespace.XMLNS;
}
else {
attNamespace = elementNode.lookupNamespaceURI(attPrefix);
if (attNamespace !== null && elementNode.isDefaultNamespace(attNamespace)) {
attNamespace = null;
}
}
if (localNameSet.has(attNamespace, attLocalName)) {
throw new Error("Element contains duplicate attributes.");
}
localNameSet.set(attNamespace, attLocalName);
if (attNamespace === infra_1.namespace.XMLNS) {
if (attValue === infra_1.namespace.XMLNS) {
throw new Error("XMLNS namespace is reserved.");
}
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)) {
throw new Error("Attribute local name contains invalid characters.");
}
if (attNamespace !== null)
elementNode.setAttributeNS(attNamespace, attName, attValue);
else
elementNode.setAttribute(attName, attValue);
}
if (!element.selfClosing) {
context = elementNode;
}
break;
case interfaces_1.TokenType.ClosingTag:
const closingTag = token;
if (closingTag.name !== context.nodeName) {
throw new Error('Closing tag name does not match opening tag name.');
}
if (context._parent) {
context = context._parent;
}
break;
}
token = lexer.nextToken();
}
return doc;
}
catch (e) {
const doc = algorithm_1.create_xmlDocument();
const root = doc.createElementNS("http://www.mozilla.org/newlayout/xml/parsererror.xml", "parsererror");
const ele = doc.createElement("error");
ele.setAttribute("message", e.message);
root.appendChild(ele);
doc.appendChild(root);
return doc;
}
}

@@ -182,0 +32,0 @@ }

@@ -10,9 +10,2 @@ import { Node } from "../dom/interfaces";

private static _VoidElementNames;
private _xmlVersion;
/**
* Initializes a new instance of `XMLSerializer`.
*
* @param xmlVersion - XML specification version
*/
constructor(xmlVersion?: "1.0" | "1.1");
/** @inheritdoc */

@@ -19,0 +12,0 @@ serializeToString(root: Node): string;

@@ -15,10 +15,2 @@ "use strict";

class XMLSerializerImpl {
/**
* Initializes a new instance of `XMLSerializer`.
*
* @param xmlVersion - XML specification version
*/
constructor(xmlVersion = "1.0") {
this._xmlVersion = xmlVersion;
}
/** @inheritdoc */

@@ -502,3 +494,3 @@ serializeToString(root) {

*/
if (requireWellFormed && (!algorithm_1.xml_isLegalChar(node.data, this._xmlVersion) ||
if (requireWellFormed && (!algorithm_1.xml_isLegalChar(node.data) ||
node.data.indexOf("--") !== -1 || node.data.endsWith("-"))) {

@@ -526,3 +518,3 @@ throw new Error("Comment data contains invalid characters (well-formed required).");

*/
if (requireWellFormed && !algorithm_1.xml_isLegalChar(node.data, this._xmlVersion)) {
if (requireWellFormed && !algorithm_1.xml_isLegalChar(node.data)) {
throw new Error("Text data contains invalid characters (well-formed required).");

@@ -601,3 +593,3 @@ }

if (requireWellFormed &&
(!algorithm_1.xml_isLegalChar(node.systemId, this._xmlVersion) ||
(!algorithm_1.xml_isLegalChar(node.systemId) ||
(node.systemId.indexOf('"') !== -1 && node.systemId.indexOf("'") !== -1))) {

@@ -666,3 +658,3 @@ throw new Error("DocType system identifier contains invalid characters (well-formed required).");

*/
if (requireWellFormed && (!algorithm_1.xml_isLegalChar(node.data, this._xmlVersion) ||
if (requireWellFormed && (!algorithm_1.xml_isLegalChar(node.data) ||
node.data.indexOf("?>") !== -1)) {

@@ -1049,3 +1041,3 @@ throw new Error("Processing instruction data contains invalid characters (well-formed required).");

*/
if (requireWellFormed && value !== null && !algorithm_1.xml_isLegalChar(value, this._xmlVersion)) {
if (requireWellFormed && value !== null && !algorithm_1.xml_isLegalChar(value)) {
throw new Error("Invalid characters in attribute value.");

@@ -1052,0 +1044,0 @@ }

{
"name": "@oozcitak/dom",
"version": "1.9.0",
"version": "1.10.0",
"keywords": [

@@ -5,0 +5,0 @@ "dom",

@@ -15,2 +15,4 @@ # DOM

This DOM implementation is for _XML documents only_.
# Installation

@@ -17,0 +19,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

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc