xmlbuilder2
Advanced tools
Comparing version 2.0.0 to 2.1.0
@@ -5,2 +5,7 @@ # Change Log | ||
## [2.1.0] - 2020-03-31 | ||
### Features | ||
- Added the `noDoubleEncoding` option to prevent html entities from being re-encoded when serialized (See [#15](https://github.com/oozcitak/xmlbuilder2/issues/15)). | ||
## [2.0.0] - 2020-03-30 | ||
@@ -7,0 +12,0 @@ |
@@ -153,15 +153,23 @@ "use strict"; | ||
} | ||
let result = ""; | ||
for (let i = 0; i < node.data.length; i++) { | ||
const c = node.data[i]; | ||
if (c === "&") | ||
result += "&"; | ||
else if (c === "<") | ||
result += "<"; | ||
else if (c === ">") | ||
result += ">"; | ||
else | ||
result += c; | ||
let markup = ""; | ||
if (this._options.noDoubleEncoding) { | ||
markup = node.data.replace(/(?!&\S+;)&/g, '&') | ||
.replace(/</g, '<') | ||
.replace(/>/g, '>') | ||
.replace(/\r/g, '
'); | ||
} | ||
this._push(this._writer.text(result)); | ||
else { | ||
for (let i = 0; i < node.data.length; i++) { | ||
const c = node.data[i]; | ||
if (c === "&") | ||
markup += "&"; | ||
else if (c === "<") | ||
markup += "<"; | ||
else if (c === ">") | ||
markup += ">"; | ||
else | ||
markup += c; | ||
} | ||
} | ||
this._push(this._writer.text(markup)); | ||
return this; | ||
@@ -565,17 +573,27 @@ } | ||
return ""; | ||
let result = ""; | ||
for (let i = 0; i < value.length; i++) { | ||
const c = value[i]; | ||
if (c === "\"") | ||
result += """; | ||
else if (c === "&") | ||
result += "&"; | ||
else if (c === "<") | ||
result += "<"; | ||
else if (c === ">") | ||
result += ">"; | ||
else | ||
result += c; | ||
if (this._options.noDoubleEncoding) { | ||
return value.replace(/(?!&\S+;)&/g, '&') | ||
.replace(/</g, '<') | ||
.replace(/"/g, '"') | ||
.replace(/\t/g, '	') | ||
.replace(/\n/g, '
') | ||
.replace(/\r/g, '
'); | ||
} | ||
return result; | ||
else { | ||
let result = ""; | ||
for (let i = 0; i < value.length; i++) { | ||
const c = value[i]; | ||
if (c === "\"") | ||
result += """; | ||
else if (c === "&") | ||
result += "&"; | ||
else if (c === "<") | ||
result += "<"; | ||
else if (c === ">") | ||
result += ">"; | ||
else | ||
result += c; | ||
} | ||
return result; | ||
} | ||
} | ||
@@ -582,0 +600,0 @@ /** |
@@ -91,3 +91,3 @@ import { Node, Document } from "@oozcitak/dom/lib/dom/interfaces"; | ||
* - char - the invalid character to be replaced | ||
* - offset - the offset of invalid character | ||
* - offset - the offset of the invalid character | ||
* - str - the input string | ||
@@ -261,2 +261,6 @@ */ | ||
wellFormed?: boolean; | ||
/** | ||
* Prevents existing html entities from being re-encoded. Defaults to `false`. | ||
*/ | ||
noDoubleEncoding?: boolean; | ||
}; | ||
@@ -1051,2 +1055,6 @@ /** | ||
wellFormed: boolean; | ||
/** | ||
* Prevents existing html entities from being re-encoded. Defaults to `false. | ||
*/ | ||
noDoubleEncoding: boolean; | ||
}; | ||
@@ -1053,0 +1061,0 @@ /** |
@@ -120,3 +120,3 @@ import { BaseWriterOptions, XMLBuilderOptions, XMLSerializedValue } from "../interfaces"; | ||
*/ | ||
serializeNode(node: Node, requireWellFormed: boolean): void; | ||
serializeNode(node: Node, requireWellFormed: boolean, noDoubleEncoding: boolean): void; | ||
/** | ||
@@ -123,0 +123,0 @@ * Produces an XML serialization of a node. |
@@ -20,2 +20,3 @@ "use strict"; | ||
wellFormed: false, | ||
noDoubleEncoding: false, | ||
prettyPrint: false, | ||
@@ -29,3 +30,5 @@ indent: ' ', | ||
const objectWriterOptions = util_1.applyDefaults(options, { | ||
format: "object" | ||
format: "object", | ||
wellFormed: false, | ||
noDoubleEncoding: false, | ||
}); | ||
@@ -32,0 +35,0 @@ const objectWriter = new ObjectWriter_1.ObjectWriter(this._builderOptions); |
@@ -20,2 +20,3 @@ "use strict"; | ||
wellFormed: false, | ||
noDoubleEncoding: false, | ||
group: false | ||
@@ -26,3 +27,4 @@ }); | ||
format: "object", | ||
wellFormed: false | ||
wellFormed: false, | ||
noDoubleEncoding: false | ||
}); | ||
@@ -29,0 +31,0 @@ const objectWriter = new ObjectWriter_1.ObjectWriter(this._builderOptions); |
@@ -20,2 +20,3 @@ "use strict"; | ||
wellFormed: false, | ||
noDoubleEncoding: false, | ||
group: false | ||
@@ -45,3 +46,3 @@ }); | ||
*/ | ||
this.serializeNode(node, options.wellFormed); | ||
this.serializeNode(node, options.wellFormed, options.noDoubleEncoding); | ||
/** | ||
@@ -48,0 +49,0 @@ * Second pass, process node lists. Above example becomes: |
@@ -26,2 +26,3 @@ "use strict"; | ||
wellFormed: false, | ||
noDoubleEncoding: false, | ||
headless: false, | ||
@@ -52,3 +53,3 @@ prettyPrint: false, | ||
} | ||
this.serializeNode(node, this._options.wellFormed); | ||
this.serializeNode(node, this._options.wellFormed, this._options.noDoubleEncoding); | ||
// remove trailing newline | ||
@@ -55,0 +56,0 @@ if (this._options.prettyPrint && |
{ | ||
"name": "xmlbuilder2", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"keywords": [ | ||
@@ -5,0 +5,0 @@ "xml", |
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
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
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
383184
6809