xmlbuilder2
Advanced tools
Comparing version 2.4.0 to 2.4.1
@@ -5,6 +5,17 @@ # Change Log | ||
## [2.4.1] - 2021-04-08 | ||
### Bug Fixes | ||
- Fixed node type dependency to `*` (see [#69](https://github.com/oozcitak/xmlbuilder2/issues/69) and [#84](https://github.com/oozcitak/xmlbuilder2/issues/84)). | ||
- Added documentation link to `next` function (see [#61](https://github.com/oozcitak/xmlbuilder2/issues/61)). | ||
- Applied `keepNullNodes` option to all types of text nodes (see [#56](https://github.com/oozcitak/xmlbuilder2/issues/56)). | ||
- Fixed a typo in `CHANGELOG` (see [#54](https://github.com/oozcitak/xmlbuilder2/issues/54)). | ||
### Features | ||
- Added `sanitize` function to parsers (see [#65](https://github.com/oozcitak/xmlbuilder2/issues/65)). | ||
## [2.4.0] - 2020-09-14 | ||
### Bug Fixes | ||
- Fixed a bug where the iput of custom parsers were not sanitized. | ||
- Fixed a bug where the input of custom parsers were not sanitized. | ||
- Fixed a bug where attributes would not lookup their namespaces from their parent elements (see [#51](https://github.com/oozcitak/xmlbuilder2/issues/51) and [#53](https://github.com/oozcitak/xmlbuilder2/issues/53)). | ||
@@ -205,1 +216,2 @@ - Fixed a bug where typings were not included in the package (see [#52](https://github.com/oozcitak/xmlbuilder2/issues/52)). | ||
[2.4.0]: https://github.com/oozcitak/xmlbuilder2/compare/v2.3.1...v2.4.0 | ||
[2.4.1]: https://github.com/oozcitak/xmlbuilder2/compare/v2.4.0...v2.4.1 |
@@ -257,2 +257,12 @@ "use strict"; | ||
XMLBuilderImpl.prototype.txt = function (content) { | ||
if (content === null || content === undefined) { | ||
if (this._options.keepNullNodes) { | ||
// keep null nodes | ||
content = ""; | ||
} | ||
else { | ||
// skip null|undefined nodes | ||
return this; | ||
} | ||
} | ||
var child = this._doc.createTextNode(dom_1.sanitizeInput(content, this._options.invalidCharReplacement)); | ||
@@ -264,2 +274,12 @@ this.node.appendChild(child); | ||
XMLBuilderImpl.prototype.com = function (content) { | ||
if (content === null || content === undefined) { | ||
if (this._options.keepNullNodes) { | ||
// keep null nodes | ||
content = ""; | ||
} | ||
else { | ||
// skip null|undefined nodes | ||
return this; | ||
} | ||
} | ||
var child = this._doc.createComment(dom_1.sanitizeInput(content, this._options.invalidCharReplacement)); | ||
@@ -271,2 +291,12 @@ this.node.appendChild(child); | ||
XMLBuilderImpl.prototype.dat = function (content) { | ||
if (content === null || content === undefined) { | ||
if (this._options.keepNullNodes) { | ||
// keep null nodes | ||
content = ""; | ||
} | ||
else { | ||
// skip null|undefined nodes | ||
return this; | ||
} | ||
} | ||
var child = this._doc.createCDATASection(dom_1.sanitizeInput(content, this._options.invalidCharReplacement)); | ||
@@ -280,2 +310,12 @@ this.node.appendChild(child); | ||
if (content === void 0) { content = ''; } | ||
if (content === null || content === undefined) { | ||
if (this._options.keepNullNodes) { | ||
// keep null nodes | ||
content = ""; | ||
} | ||
else { | ||
// skip null|undefined nodes | ||
return this; | ||
} | ||
} | ||
if (util_1.isArray(target) || util_1.isSet(target)) { | ||
@@ -282,0 +322,0 @@ util_1.forEachArray(target, function (item) { |
@@ -334,2 +334,8 @@ import { Node, Document } from "@oozcitak/dom/lib/dom/interfaces"; | ||
attribute?: (parent: XMLBuilder, namespace: string | null | undefined, name: string, value: string) => XMLBuilder | undefined; | ||
/** | ||
* Sanitizes input strings. | ||
* | ||
* @param str - input string | ||
*/ | ||
sanitize?(str: string): string; | ||
}; | ||
@@ -336,0 +342,0 @@ /** |
@@ -21,2 +21,3 @@ import { XMLBuilderOptions, ExpandObject, XMLBuilder } from "../interfaces"; | ||
_attribute(parent: XMLBuilder, namespace: string | null | undefined, name: string, value: string): XMLBuilder | undefined; | ||
_sanitize(str: string): string; | ||
/** | ||
@@ -90,2 +91,8 @@ * Main parser function which parses the given object and returns an XMLBuilder. | ||
attribute(parent: XMLBuilder, namespace: string | null | undefined, name: string, value: string): XMLBuilder | undefined; | ||
/** | ||
* Sanitizes input strings. | ||
* | ||
* @param str - input string | ||
*/ | ||
sanitize(str: string): string; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var dom_1 = require("../builder/dom"); | ||
/** | ||
@@ -39,2 +40,5 @@ * Pre-serializes XML nodes. | ||
}; | ||
BaseReader.prototype._sanitize = function (str) { | ||
return dom_1.sanitizeInput(str, this._builderOptions.invalidCharReplacement); | ||
}; | ||
/** | ||
@@ -124,2 +128,10 @@ * Main parser function which parses the given object and returns an XMLBuilder. | ||
}; | ||
/** | ||
* Sanitizes input strings. | ||
* | ||
* @param str - input string | ||
*/ | ||
BaseReader.prototype.sanitize = function (str) { | ||
return this._sanitize(str); | ||
}; | ||
return BaseReader; | ||
@@ -126,0 +138,0 @@ }()); |
@@ -18,3 +18,2 @@ "use strict"; | ||
var BaseReader_1 = require("./BaseReader"); | ||
var dom_1 = require("../builder/dom"); | ||
/** | ||
@@ -38,7 +37,2 @@ * Parses XML nodes from objects and arrays. | ||
var options = this._builderOptions; | ||
// sanitizes input characters | ||
var invalidCharReplacement = options.invalidCharReplacement; | ||
var s = function (str) { | ||
return dom_1.sanitizeInput(str, invalidCharReplacement); | ||
}; | ||
var lastChild = null; | ||
@@ -67,3 +61,3 @@ if (util_1.isFunction(obj)) { | ||
util_1.forEachObject(val, function (attrKey, attrVal) { | ||
lastChild = _this.attribute(node, undefined, s(attrKey), s(attrVal)) || lastChild; | ||
lastChild = _this.attribute(node, undefined, _this.sanitize(attrKey), _this.sanitize(attrVal)) || lastChild; | ||
}); | ||
@@ -73,3 +67,3 @@ } | ||
else { | ||
lastChild = _this.attribute(node, undefined, s(key.substr(options.convert.att.length)), s(val)) || lastChild; | ||
lastChild = _this.attribute(node, undefined, _this.sanitize(key.substr(options.convert.att.length)), _this.sanitize(val)) || lastChild; | ||
} | ||
@@ -84,3 +78,3 @@ } | ||
else { | ||
lastChild = _this.text(node, s(val)) || lastChild; | ||
lastChild = _this.text(node, _this.sanitize(val)) || lastChild; | ||
} | ||
@@ -91,6 +85,6 @@ } | ||
if (util_1.isArray(val) || util_1.isSet(val)) { | ||
util_1.forEachArray(val, function (item) { return lastChild = _this.cdata(node, s(item)) || lastChild; }, _this); | ||
util_1.forEachArray(val, function (item) { return lastChild = _this.cdata(node, _this.sanitize(item)) || lastChild; }, _this); | ||
} | ||
else { | ||
lastChild = _this.cdata(node, s(val)) || lastChild; | ||
lastChild = _this.cdata(node, _this.sanitize(val)) || lastChild; | ||
} | ||
@@ -101,6 +95,6 @@ } | ||
if (util_1.isArray(val) || util_1.isSet(val)) { | ||
util_1.forEachArray(val, function (item) { return lastChild = _this.comment(node, s(item)) || lastChild; }, _this); | ||
util_1.forEachArray(val, function (item) { return lastChild = _this.comment(node, _this.sanitize(item)) || lastChild; }, _this); | ||
} | ||
else { | ||
lastChild = _this.comment(node, s(val)) || lastChild; | ||
lastChild = _this.comment(node, _this.sanitize(val)) || lastChild; | ||
} | ||
@@ -114,3 +108,3 @@ } | ||
var insValue = (insIndex === -1 ? '' : val.substr(insIndex + 1)); | ||
lastChild = _this.instruction(node, s(insTarget), s(insValue)) || lastChild; | ||
lastChild = _this.instruction(node, _this.sanitize(insTarget), _this.sanitize(insValue)) || lastChild; | ||
} | ||
@@ -122,7 +116,7 @@ else if (util_1.isArray(val) || util_1.isSet(val)) { | ||
var insValue = (insIndex === -1 ? '' : item.substr(insIndex + 1)); | ||
lastChild = _this.instruction(node, s(insTarget), s(insValue)) || lastChild; | ||
lastChild = _this.instruction(node, _this.sanitize(insTarget), _this.sanitize(insValue)) || lastChild; | ||
}, _this); | ||
} | ||
else /* if (isMap(target) || isObject(target)) */ { | ||
util_1.forEachObject(val, function (insTarget, insValue) { return lastChild = _this.instruction(node, s(insTarget), s(insValue)) || lastChild; }, _this); | ||
util_1.forEachObject(val, function (insTarget, insValue) { return lastChild = _this.instruction(node, _this.sanitize(insTarget), _this.sanitize(insValue)) || lastChild; }, _this); | ||
} | ||
@@ -135,3 +129,3 @@ } | ||
// empty objects produce one node | ||
lastChild = _this.element(node, undefined, s(key)) || lastChild; | ||
lastChild = _this.element(node, undefined, _this.sanitize(key)) || lastChild; | ||
} | ||
@@ -151,3 +145,3 @@ else if (!options.keepNullNodes && (val == null)) { | ||
// create a parent node | ||
var parent = _this.element(node, undefined, key); | ||
var parent = _this.element(node, undefined, _this.sanitize(key)); | ||
if (parent) { | ||
@@ -161,6 +155,6 @@ lastChild = parent; | ||
// leaf element node with a single text node | ||
var parent = _this.element(node, undefined, key); | ||
var parent = _this.element(node, undefined, _this.sanitize(key)); | ||
if (parent) { | ||
lastChild = parent; | ||
_this.text(parent, s(val)); | ||
_this.text(parent, _this.sanitize(val)); | ||
} | ||
@@ -170,3 +164,3 @@ } | ||
// leaf element node | ||
lastChild = _this.element(node, undefined, s(key)) || lastChild; | ||
lastChild = _this.element(node, undefined, _this.sanitize(key)) || lastChild; | ||
} | ||
@@ -173,0 +167,0 @@ }, this); |
@@ -47,3 +47,2 @@ "use strict"; | ||
var algorithm_1 = require("@oozcitak/dom/lib/algorithm"); | ||
var dom_1 = require("../builder/dom"); | ||
var BaseReader_1 = require("./BaseReader"); | ||
@@ -67,7 +66,2 @@ /** | ||
var lexer = new XMLStringLexer_1.XMLStringLexer(str, { skipWhitespaceOnlyText: true }); | ||
// sanitizes input characters | ||
var invalidCharReplacement = this._builderOptions.invalidCharReplacement; | ||
var s = function (str) { | ||
return dom_1.sanitizeInput(str, invalidCharReplacement); | ||
}; | ||
var context = node; | ||
@@ -79,3 +73,3 @@ var token = lexer.nextToken(); | ||
var declaration = token; | ||
var version = s(declaration.version); | ||
var version = this.sanitize(declaration.version); | ||
if (version !== "1.0") { | ||
@@ -88,6 +82,6 @@ throw new Error("Invalid xml version: " + version); | ||
if (declaration.encoding) { | ||
builderOptions.encoding = s(declaration.encoding); | ||
builderOptions.encoding = this.sanitize(declaration.encoding); | ||
} | ||
if (declaration.standalone) { | ||
builderOptions.standalone = (s(declaration.standalone) === "yes"); | ||
builderOptions.standalone = (this.sanitize(declaration.standalone) === "yes"); | ||
} | ||
@@ -98,23 +92,23 @@ context.set(builderOptions); | ||
var doctype = token; | ||
context = this.docType(context, s(doctype.name), s(doctype.pubId), s(doctype.sysId)) || context; | ||
context = this.docType(context, this.sanitize(doctype.name), this.sanitize(doctype.pubId), this.sanitize(doctype.sysId)) || context; | ||
break; | ||
case interfaces_1.TokenType.CDATA: | ||
var cdata = token; | ||
context = this.cdata(context, s(cdata.data)) || context; | ||
context = this.cdata(context, this.sanitize(cdata.data)) || context; | ||
break; | ||
case interfaces_1.TokenType.Comment: | ||
var comment = token; | ||
context = this.comment(context, s(comment.data)) || context; | ||
context = this.comment(context, this.sanitize(comment.data)) || context; | ||
break; | ||
case interfaces_1.TokenType.PI: | ||
var pi = token; | ||
context = this.instruction(context, s(pi.target), s(pi.data)) || context; | ||
context = this.instruction(context, this.sanitize(pi.target), this.sanitize(pi.data)) || context; | ||
break; | ||
case interfaces_1.TokenType.Text: | ||
var text = token; | ||
context = this.text(context, s(text.data)) || context; | ||
context = this.text(context, this.sanitize(text.data)) || context; | ||
break; | ||
case interfaces_1.TokenType.Element: | ||
var element = token; | ||
var elementName = s(element.name); | ||
var elementName = this.sanitize(element.name); | ||
// inherit namespace from parent | ||
@@ -130,4 +124,4 @@ var _c = __read(algorithm_1.namespace_extractQName(elementName), 1), prefix = _c[0]; | ||
var _f = __read(_e.value, 2), attName = _f[0], attValue = _f[1]; | ||
attName = s(attName); | ||
attValue = s(attValue); | ||
attName = this.sanitize(attName); | ||
attValue = this.sanitize(attValue); | ||
if (attName === "xmlns") { | ||
@@ -164,4 +158,4 @@ namespace = attValue; | ||
var _k = __read(_j.value, 2), attName = _k[0], attValue = _k[1]; | ||
attName = s(attName); | ||
attValue = s(attValue); | ||
attName = this.sanitize(attName); | ||
attValue = this.sanitize(attValue); | ||
var _l = __read(algorithm_1.namespace_extractQName(attName), 2), attPrefix = _l[0], attLocalName = _l[1]; | ||
@@ -168,0 +162,0 @@ var attNamespace = null; |
{ | ||
"name": "xmlbuilder2", | ||
"version": "2.4.0", | ||
"version": "2.4.1", | ||
"keywords": [ | ||
@@ -30,7 +30,7 @@ "xml", | ||
"dependencies": { | ||
"@oozcitak/util": "8.3.8", | ||
"@oozcitak/dom": "1.15.8", | ||
"@oozcitak/infra": "1.0.8", | ||
"js-yaml": "3.14.0", | ||
"@types/node": "14.6.2" | ||
"@oozcitak/util": "8.3.8", | ||
"@types/node": "*", | ||
"js-yaml": "3.14.0" | ||
}, | ||
@@ -43,4 +43,4 @@ "devDependencies": { | ||
"@types/jest": "*", | ||
"@types/js-yaml": "3.11.1", | ||
"@types/libxmljs": "*", | ||
"@types/js-yaml": "3.11.1", | ||
"babel-loader": "*", | ||
@@ -51,4 +51,4 @@ "benchmark": "*", | ||
"dedent": "*", | ||
"es6-proxy-polyfill": "*", | ||
"glob": "*", | ||
"es6-proxy-polyfill": "*", | ||
"harmony-reflect": "*", | ||
@@ -64,9 +64,3 @@ "jest": "*", | ||
"xmlbuilder": "*", | ||
"xpath": "*", | ||
"selenium-webdriver": "*", | ||
"chromedriver": "*", | ||
"geckodriver": "*", | ||
"iedriver": "*", | ||
"@types/selenium-webdriver": "*", | ||
"@types/chromedriver": "*" | ||
"xpath": "*" | ||
}, | ||
@@ -78,5 +72,2 @@ "jest": { | ||
"testRegex": "/test/.*\\.test\\.tsx?$", | ||
"testPathIgnorePatterns": [ | ||
"/test/browser/.*" | ||
], | ||
"testEnvironment": "node", | ||
@@ -83,0 +74,0 @@ "collectCoverageFrom": [ |
@@ -0,0 +0,0 @@ # xmlbuilder2 |
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
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
1088696
25
9424
+ Added@types/node@22.9.0(transitive)
+ Addedundici-types@6.19.8(transitive)
- Removed@types/node@14.6.2(transitive)
Updated@types/node@*