Socket
Socket
Sign inDemoInstall

xmlbuilder2

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xmlbuilder2 - npm Package Compare versions

Comparing version 1.1.1 to 1.1.2

7

lib/builder/XMLBuilderImpl.d.ts

@@ -129,2 +129,9 @@ import { XMLBuilderOptions, XMLBuilder, AttributesObject, ExpandObject, WriterOptions, XMLSerializedValue, DTDOptions, PIObject } from "./interfaces";

/**
* Extracts a namespace and name from the given string.
*
* @param str - a string containing both a name and namespace separated by an
* '@' character.
*/
private _extractNamespace;
/**
* Returns the document owning this node.

@@ -131,0 +138,0 @@ */

94

lib/builder/XMLBuilderImpl.js

@@ -5,6 +5,4 @@ "use strict";

const util_1 = require("@oozcitak/util");
const infra_1 = require("@oozcitak/infra");
const writers_1 = require("../writers");
const dom_1 = require("./dom");
const algorithm_1 = require("@oozcitak/dom/lib/algorithm");
const util_2 = require("@oozcitak/dom/lib/util");

@@ -73,7 +71,8 @@ /**

// ele(name: string, attributes: AttributesObject)
[namespace, name, attributes] = [undefined, p1, p2];
[namespace, name] = this._extractNamespace(p1);
attributes = p2;
}
else {
// ele(name: string)
[namespace, name, attributes] = [undefined, p1, undefined];
[namespace, name] = this._extractNamespace(p1);
}

@@ -167,16 +166,5 @@ if (attributes) {

else if (util_1.isMap(val) || util_1.isObject(val)) {
// check for a namespace declaration attribute
let attNamespace;
const qName = algorithm_1.namespace_extractQName(key);
util_1.forEachObject(val, (attName, attValue) => {
if (attName[0] === this._options.convert.att) {
const attQName = algorithm_1.namespace_extractQName(attName.slice(1));
if ((attQName[0] === null && attQName[1] === "xmlns") ||
(attQName[0] === "xmlns" && attQName[1] === qName[0])) {
attNamespace = attValue;
}
}
}, this);
// create a parent node
lastChild = this._node(attNamespace, key);
[namespace, name] = this._extractNamespace(key);
lastChild = this._node(namespace, name);
// expand child nodes under parent

@@ -236,3 +224,4 @@ lastChild.ele(val);

// ele(name: string, value: string)
[namespace, name, value] = [undefined, p1, p2];
[namespace, name] = this._extractNamespace(p1);
value = p2;
}

@@ -250,30 +239,8 @@ else {

}
// xmlns defaults to XMLNS namespace
if ((namespace === null || namespace === undefined) && name === "xmlns") {
namespace = infra_1.namespace.XMLNS;
}
const ele = this.node;
// convert to string
if (namespace !== undefined && namespace !== null)
namespace += "";
name += "";
value += "";
// check if this is a namespace declaration attribute
if (namespace === undefined) {
const attQName = algorithm_1.namespace_extractQName(name);
if (attQName[0] === "xmlns") {
namespace = infra_1.namespace.XMLNS;
}
else if (attQName[0] !== null) {
namespace = ele.lookupNamespaceURI(attQName[0]);
}
else {
namespace = ele.lookupNamespaceURI(attQName[0]);
}
if (namespace !== null && namespace !== undefined) {
ele.setAttributeNS(namespace + "", name + "", value + "");
}
if (namespace !== null && namespace !== undefined && !ele.isDefaultNamespace(namespace)) {
ele.setAttributeNS(namespace, name, value);
}
else {
ele.setAttribute(name, value);
ele.setAttribute(name + "", value + "");
}

@@ -638,30 +605,6 @@ return this;

name += "";
// inherit namespace from parent
if (namespace === null || namespace === undefined) {
const qName = algorithm_1.namespace_extractQName(name);
const parent = this.node.parentNode;
if (parent) {
namespace = parent.lookupNamespaceURI(qName[0]);
}
// override namespace if there is a namespace declaration
// attribute
if (attributes !== undefined) {
util_1.forEachObject(attributes, (attName, attValue) => {
if (attName === "xmlns") {
namespace = attValue;
}
else {
const attQName = algorithm_1.namespace_extractQName(attName);
if (attQName[0] === "xmlns" && attQName[1] === qName[0]) {
namespace = attValue;
}
}
});
}
}
const node = this.node;
const child = (namespace !== null && namespace !== undefined ?
this._doc.createElementNS(namespace + "", name) :
this._doc.createElement(name));
node.appendChild(child);
this.node.appendChild(child);
const builder = new XMLBuilderImpl(child);

@@ -694,2 +637,17 @@ // update doctype node if the new node is the document element node

/**
* Extracts a namespace and name from the given string.
*
* @param str - a string containing both a name and namespace separated by an
* '@' character.
*/
_extractNamespace(str) {
const atIndex = str.indexOf("@");
if (atIndex <= 0) {
return [undefined, str];
}
else {
return [str.slice(atIndex + 1), str.slice(0, atIndex)];
}
}
/**
* Returns the document owning this node.

@@ -696,0 +654,0 @@ */

{
"name": "xmlbuilder2",
"version": "1.1.1",
"version": "1.1.2",
"keywords": [

@@ -37,2 +37,3 @@ "xml",

"@types/jest": "*",
"@types/libxmljs": "*",
"@types/node": "*",

@@ -44,2 +45,3 @@ "benchmark": "*",

"jest": "*",
"libxmljs": "*",
"ts-jest": "*",

@@ -46,0 +48,0 @@ "ts-node": "*",

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