Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

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 2.1.2 to 2.1.3

6

CHANGELOG.md

@@ -5,2 +5,8 @@ # Change Log

## [2.1.3] - 2020-06-11
### Bug Fixes
- Fixed a bug where child nodes did not inherit the parent namespace (see [#18](https://github.com/oozcitak/xmlbuilder2/issues/18)).
- Fixed a bug where falsey values passed as node contents caused missing nodes (see [#21](https://github.com/oozcitak/xmlbuilder2/issues/21)).
## [2.1.2] - 2020-04-09

@@ -7,0 +13,0 @@

@@ -132,2 +132,8 @@ import { XMLBuilderOptions, XMLBuilder, AttributesObject, ExpandObject, WriterOptions, DTDOptions, PIObject, XMLWriterOptions, JSONWriterOptions, ObjectWriterOptions, MapWriterOptions } from "../interfaces";

/**
* Updates the element's namespace.
*
* @param ns - new namespace
*/
private _updateNamespace;
/**
* Returns the document owning this node.

@@ -134,0 +140,0 @@ */

79

lib/builder/XMLBuilderImpl.js

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

}
else if (val) {
else if (val != null && val !== '') {
// leaf element node with a single text node

@@ -263,3 +263,3 @@ lastChild = this.ele(key);

const [prefix, localName] = algorithm_1.namespace_extractQName(name);
const [elePrefix, eleLocalName] = algorithm_1.namespace_extractQName(ele.prefix ? ele.prefix + ':' + ele.localName : ele.localName);
const [elePrefix] = algorithm_1.namespace_extractQName(ele.prefix ? ele.prefix + ':' + ele.localName : ele.localName);
// check if this is a namespace declaration attribute

@@ -281,17 +281,4 @@ // assign a new element namespace if it wasn't previously assigned

if (eleNamespace !== null) {
const newEle = algorithm_1.create_element(this._doc, eleLocalName, eleNamespace, elePrefix);
for (const attr of ele.attributes) {
newEle.setAttributeNodeNS(attr.cloneNode());
}
for (const childNode of ele.childNodes) {
newEle.appendChild(childNode.cloneNode());
}
const parent = ele.parentNode;
/* istanbul ignore next */
if (parent === null) {
throw new Error("Parent node is null." + this._debugInfo());
}
parent.replaceChild(newEle, ele);
this._domNode = newEle;
ele = newEle;
this._updateNamespace(eleNamespace);
ele = this.node;
}

@@ -425,2 +412,5 @@ if (namespace !== undefined) {

hostNode.appendChild(clone);
const [prefix] = algorithm_1.namespace_extractQName(clone.prefix ? clone.prefix + ':' + clone.localName : clone.localName);
const namespace = hostNode.lookupNamespaceURI(prefix);
new XMLBuilderImpl(clone)._updateNamespace(namespace);
}

@@ -432,2 +422,7 @@ else if (util_2.Guard.isDocumentFragmentNode(importedNode)) {

hostNode.appendChild(clone);
if (util_2.Guard.isElementNode(clone)) {
const [prefix] = algorithm_1.namespace_extractQName(clone.prefix ? clone.prefix + ':' + clone.localName : clone.localName);
const namespace = hostNode.lookupNamespaceURI(prefix);
new XMLBuilderImpl(clone)._updateNamespace(namespace);
}
}

@@ -439,2 +434,7 @@ }

hostNode.appendChild(clone);
if (util_2.Guard.isElementNode(clone)) {
const [prefix] = algorithm_1.namespace_extractQName(clone.prefix ? clone.prefix + ':' + clone.localName : clone.localName);
const namespace = hostNode.lookupNamespaceURI(prefix);
new XMLBuilderImpl(clone)._updateNamespace(namespace);
}
}

@@ -452,3 +452,3 @@ return this;

if (node === null) {
throw new Error("Node has no parent node while searching for document fragment ancestor.");
throw new Error("Node has no parent node while searching for document fragment ancestor. " + this._debugInfo());
}

@@ -733,2 +733,45 @@ return new XMLBuilderImpl(node);

/**
* Updates the element's namespace.
*
* @param ns - new namespace
*/
_updateNamespace(ns) {
const ele = this._domNode;
if (util_2.Guard.isElementNode(ele) && ns !== null && ele.namespaceURI !== ns) {
const [elePrefix, eleLocalName] = algorithm_1.namespace_extractQName(ele.prefix ? ele.prefix + ':' + ele.localName : ele.localName);
// re-create the element node if its namespace changed
// we can't simply change the namespaceURI since its read-only
const newEle = algorithm_1.create_element(this._doc, eleLocalName, ns, elePrefix);
for (const attr of ele.attributes) {
const attrQName = attr.prefix ? attr.prefix + ':' + attr.localName : attr.localName;
const [attrPrefix] = algorithm_1.namespace_extractQName(attrQName);
if (attrPrefix === null) {
newEle.setAttribute(attrQName, attr.value);
}
else {
const newAttrNS = newEle.lookupNamespaceURI(attrPrefix);
newEle.setAttributeNS(newAttrNS, attrQName, attr.value);
}
}
// replace the new node in parent node
const parent = ele.parentNode;
/* istanbul ignore next */
if (parent === null) {
throw new Error("Parent node is null." + this._debugInfo());
}
parent.replaceChild(newEle, ele);
this._domNode = newEle;
// check child nodes
for (const childNode of ele.childNodes) {
const newChildNode = childNode.cloneNode(true);
newEle.appendChild(newChildNode);
if (util_2.Guard.isElementNode(newChildNode)) {
const [newChildNodePrefix] = algorithm_1.namespace_extractQName(newChildNode.prefix ? newChildNode.prefix + ':' + newChildNode.localName : newChildNode.localName);
const newChildNodeNS = newEle.lookupNamespaceURI(newChildNodePrefix);
new XMLBuilderImpl(newChildNode)._updateNamespace(newChildNodeNS);
}
}
}
}
/**
* Returns the document owning this node.

@@ -735,0 +778,0 @@ */

{
"name": "xmlbuilder2",
"version": "2.1.2",
"version": "2.1.3",
"keywords": [

@@ -5,0 +5,0 @@ "xml",

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