@xmldom/xmldom 0.7.3 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +51 -0
- package/SECURITY.md +50 -0
- package/lib/dom-parser.js +68 -14
- package/lib/dom.js +94 -36
- package/lib/sax.js +35 -27
- package/package.json +26 -14
- package/readme.md +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,57 @@ All notable changes to this project will be documented in this file.
|
|
|
4
4
|
|
|
5
5
|
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
6
|
|
|
7
|
+
## [0.8.1](https://github.com/xmldom/xmldom/compare/0.8.0...0.8.1)
|
|
8
|
+
|
|
9
|
+
### Fixes
|
|
10
|
+
- Only use own properties in entityMap [`#374`](https://github.com/xmldom/xmldom/pull/374)
|
|
11
|
+
|
|
12
|
+
### Docs
|
|
13
|
+
- Add security policy [`#365`](https://github.com/xmldom/xmldom/pull/365)
|
|
14
|
+
- changelog: Correct contributor name and link [`#366`](https://github.com/xmldom/xmldom/pull/366)
|
|
15
|
+
- Describe release/publish steps [`#358`](https://github.com/xmldom/xmldom/pull/358), [`#376`](https://github.com/xmldom/xmldom/pull/376)
|
|
16
|
+
- Add snyk package health badge [`#360`](https://github.com/xmldom/xmldom/pull/360)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
## [0.8.0](https://github.com/xmldom/xmldom/compare/0.7.5...0.8.0)
|
|
20
|
+
|
|
21
|
+
### Fixed
|
|
22
|
+
- Normalize all line endings according to XML specs [1.0](https://w3.org/TR/xml/#sec-line-ends) and [1.1](https://www.w3.org/TR/xml11/#sec-line-ends) \
|
|
23
|
+
BREAKING CHANGE: Certain combination of line break characters are normalized to a single `\n` before parsing takes place and will no longer be preserved.
|
|
24
|
+
- [`#303`](https://github.com/xmldom/xmldom/issues/303) / [`#307`](https://github.com/xmldom/xmldom/pull/307)
|
|
25
|
+
- [`#49`](https://github.com/xmldom/xmldom/issues/49), [`#97`](https://github.com/xmldom/xmldom/issues/97), [`#324`](https://github.com/xmldom/xmldom/issues/324) / [`#314`](https://github.com/xmldom/xmldom/pull/314)
|
|
26
|
+
- XMLSerializer: Preserve whitespace character references [`#284`](https://github.com/xmldom/xmldom/issues/284) / [`#310`](https://github.com/xmldom/xmldom/pull/310) \
|
|
27
|
+
BREAKING CHANGE: If you relied on the not spec compliant preservation of literal `\t`, `\n` or `\r` in **attribute values**.
|
|
28
|
+
To preserve those you will have to create XML that instead contains the correct numerical (or hexadecimal) equivalent (e.g. `	`, `
`, `
`).
|
|
29
|
+
- Drop deprecated exports `DOMImplementation` and `XMLSerializer` from `lib/dom-parser.js` [#53](https://github.com/xmldom/xmldom/issues/53) / [`#309`](https://github.com/xmldom/xmldom/pull/309)
|
|
30
|
+
BREAKING CHANGE: Use the one provided by the main package export.
|
|
31
|
+
- dom: Remove all links as part of `removeChild` [`#343`](https://github.com/xmldom/xmldom/issues/343) / [`#355`](https://github.com/xmldom/xmldom/pull/355)
|
|
32
|
+
|
|
33
|
+
### Chore
|
|
34
|
+
- ci: Restore latest tested node version to 16.x [`#325`](https://github.com/xmldom/xmldom/pull/325)
|
|
35
|
+
- ci: Split test and lint steps into jobs [`#111`](https://github.com/xmldom/xmldom/issues/111) / [`#304`](https://github.com/xmldom/xmldom/pull/304)
|
|
36
|
+
- Pinned and updated devDependencies
|
|
37
|
+
|
|
38
|
+
Thank you [@marrus-sh](https://github.com/marrus-sh), [@victorandree](https://github.com/victorandree), [@mdierolf](https://github.com/mdierolf), [@tsabbay](https://github.com/tsabbay), [@fatihpense](https://github.com/fatihpense) for your contributions
|
|
39
|
+
|
|
40
|
+
## 0.7.5
|
|
41
|
+
|
|
42
|
+
[Commits](https://github.com/xmldom/xmldom/compare/0.7.4...0.7.5)
|
|
43
|
+
|
|
44
|
+
### Fixes:
|
|
45
|
+
|
|
46
|
+
- Preserve default namespace when serializing [`#319`](https://github.com/xmldom/xmldom/issues/319) / [`#321`](https://github.com/xmldom/xmldom/pull/321)
|
|
47
|
+
Thank you [@lupestro](https://github.com/lupestro)
|
|
48
|
+
|
|
49
|
+
## 0.7.4
|
|
50
|
+
|
|
51
|
+
[Commits](https://github.com/xmldom/xmldom/compare/0.7.3...0.7.4)
|
|
52
|
+
|
|
53
|
+
### Fixes:
|
|
54
|
+
|
|
55
|
+
- Restore ability to parse `__prototype__` attributes [`#315`](https://github.com/xmldom/xmldom/pull/315)
|
|
56
|
+
Thank you [@dsimpsonOMF](https://github.com/dsimpsonOMF)
|
|
57
|
+
|
|
7
58
|
## 0.7.3
|
|
8
59
|
|
|
9
60
|
[Commits](https://github.com/xmldom/xmldom/compare/0.7.2...0.7.3)
|
package/SECURITY.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# Security Policy
|
|
2
|
+
|
|
3
|
+
The most up-to-date version of this document can be found at <https://github.com/xmldom/xmldom/security/policy>.
|
|
4
|
+
|
|
5
|
+
## Supported Versions
|
|
6
|
+
|
|
7
|
+
This repository contains the code for the libraries `xmldom` and `@xmldom/xmldom` on npm.
|
|
8
|
+
|
|
9
|
+
As long as we didn't publish v1, we aim to maintain the last two minor versions with security fixes. If it is possible we provide security fixes as path versions.
|
|
10
|
+
If you think there is a good reason to also patch an earlier version let us know in a github issue or the release discussion once the fix has been provided.
|
|
11
|
+
The maintainers will consider it and if we agree and have/find the required resources, a patch for that version will be provided.
|
|
12
|
+
|
|
13
|
+
Please notice that [we are no longer able to publish the (unscoped) `xmldom` package](https://github.com/xmldom/xmldom/issues/271),
|
|
14
|
+
and that all existing versions of `xmldom` are affected by at least one security vulnerability and should be considered deprecated.
|
|
15
|
+
You can still report issues regarding `xmldom` as described below.
|
|
16
|
+
|
|
17
|
+
If you need help with migrating from `xmldom` to `@xmldom/xmldom`, file a github issue or PR in the affected repository and mention @karfau.
|
|
18
|
+
|
|
19
|
+
## Reporting vulnerabilities
|
|
20
|
+
|
|
21
|
+
Please email reports about any security related issues you find to `security@xmldom.org`, which will forward it to the list of maintainers.
|
|
22
|
+
The maintainers will try to respond within 7 calendar days. (If nobody peplies after 7 days, please us send a reminder!)
|
|
23
|
+
As part of you communication please make sure to always hit "Reply all", so all maintainers are kept in the loop.
|
|
24
|
+
|
|
25
|
+
In addition, please include the following information along with your report:
|
|
26
|
+
|
|
27
|
+
- Your name and affiliation (if any).
|
|
28
|
+
- A description of the technical details of the vulnerabilities. It is very important to let us know how we can reproduce your findings.
|
|
29
|
+
- An explanation who can exploit this vulnerability, and what they gain when doing so -- write an attack scenario. This will help us evaluate your report quickly, especially if the issue is complex.
|
|
30
|
+
- Whether this vulnerability public or known to third parties. If it is, please provide details.
|
|
31
|
+
|
|
32
|
+
If you believe that an existing (public) issue is security-related, please send an email to `security@xmldom.org`.
|
|
33
|
+
The email should include the issue URL and a short description of why it should be handled according to this security policy.
|
|
34
|
+
|
|
35
|
+
Once an issue is reported, the maintainers use the following disclosure process:
|
|
36
|
+
|
|
37
|
+
- When a report is received, we confirm the issue, determine its severity and the affected versions.
|
|
38
|
+
- If we know of specific third-party services or software based on xmldom that require mitigation before publication, those projects will be notified.
|
|
39
|
+
- A [github security advisory](https://docs.github.com/en/code-security/security-advisories/about-github-security-advisories) is [created](https://docs.github.com/en/code-security/security-advisories/creating-a-security-advisory) (but not published) which details the problem and steps for mitigation.
|
|
40
|
+
- If the reporter provides a github account and agrees to it, we (add that github account as a collaborator on the advisuory)[https://docs.github.com/en/code-security/security-advisories/adding-a-collaborator-to-a-security-advisory].
|
|
41
|
+
- The vulnerability is fixed in a [private fork](https://docs.github.com/en/code-security/security-advisories/collaborating-in-a-temporary-private-fork-to-resolve-a-security-vulnerability) and potential workarounds are identified.
|
|
42
|
+
- The maintainers audit the existing code to find any potential similar problems.
|
|
43
|
+
- The release for the current minor version and the [security advisory are published](https://docs.github.com/en/code-security/security-advisories/publishing-a-security-advisory).
|
|
44
|
+
- The release(s) for previous minor version(s) are published.
|
|
45
|
+
|
|
46
|
+
We credit reporters for identifying security issues, if they confirm that they want to.
|
|
47
|
+
|
|
48
|
+
## Known vulnerabilities
|
|
49
|
+
|
|
50
|
+
See https://github.com/xmldom/xmldom/security/advisories?state=published
|
package/lib/dom-parser.js
CHANGED
|
@@ -10,6 +10,64 @@ var NAMESPACE = conventions.NAMESPACE;
|
|
|
10
10
|
var ParseError = sax.ParseError;
|
|
11
11
|
var XMLReader = sax.XMLReader;
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Normalizes line ending according to https://www.w3.org/TR/xml11/#sec-line-ends:
|
|
15
|
+
*
|
|
16
|
+
* > XML parsed entities are often stored in computer files which,
|
|
17
|
+
* > for editing convenience, are organized into lines.
|
|
18
|
+
* > These lines are typically separated by some combination
|
|
19
|
+
* > of the characters CARRIAGE RETURN (#xD) and LINE FEED (#xA).
|
|
20
|
+
* >
|
|
21
|
+
* > To simplify the tasks of applications, the XML processor must behave
|
|
22
|
+
* > as if it normalized all line breaks in external parsed entities (including the document entity)
|
|
23
|
+
* > on input, before parsing, by translating all of the following to a single #xA character:
|
|
24
|
+
* >
|
|
25
|
+
* > 1. the two-character sequence #xD #xA
|
|
26
|
+
* > 2. the two-character sequence #xD #x85
|
|
27
|
+
* > 3. the single character #x85
|
|
28
|
+
* > 4. the single character #x2028
|
|
29
|
+
* > 5. any #xD character that is not immediately followed by #xA or #x85.
|
|
30
|
+
*
|
|
31
|
+
* @param {string} input
|
|
32
|
+
* @returns {string}
|
|
33
|
+
*/
|
|
34
|
+
function normalizeLineEndings(input) {
|
|
35
|
+
return input
|
|
36
|
+
.replace(/\r[\n\u0085]/g, '\n')
|
|
37
|
+
.replace(/[\r\u0085\u2028]/g, '\n')
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @typedef Locator
|
|
42
|
+
* @property {number} [columnNumber]
|
|
43
|
+
* @property {number} [lineNumber]
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @typedef DOMParserOptions
|
|
48
|
+
* @property {DOMHandler} [domBuilder]
|
|
49
|
+
* @property {Function} [errorHandler]
|
|
50
|
+
* @property {(string) => string} [normalizeLineEndings] used to replace line endings before parsing
|
|
51
|
+
* defaults to `normalizeLineEndings`
|
|
52
|
+
* @property {Locator} [locator]
|
|
53
|
+
* @property {Record<string, string>} [xmlns]
|
|
54
|
+
*
|
|
55
|
+
* @see normalizeLineEndings
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The DOMParser interface provides the ability to parse XML or HTML source code
|
|
60
|
+
* from a string into a DOM `Document`.
|
|
61
|
+
*
|
|
62
|
+
* _xmldom is different from the spec in that it allows an `options` parameter,
|
|
63
|
+
* to override the default behavior._
|
|
64
|
+
*
|
|
65
|
+
* @param {DOMParserOptions} [options]
|
|
66
|
+
* @constructor
|
|
67
|
+
*
|
|
68
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/DOMParser
|
|
69
|
+
* @see https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-parsing-and-serialization
|
|
70
|
+
*/
|
|
13
71
|
function DOMParser(options){
|
|
14
72
|
this.options = options ||{locator:{}};
|
|
15
73
|
}
|
|
@@ -33,10 +91,15 @@ DOMParser.prototype.parseFromString = function(source,mimeType){
|
|
|
33
91
|
defaultNSMap[''] = NAMESPACE.HTML;
|
|
34
92
|
}
|
|
35
93
|
defaultNSMap.xml = defaultNSMap.xml || NAMESPACE.XML;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
94
|
+
var normalize = options.normalizeLineEndings || normalizeLineEndings;
|
|
95
|
+
if (source && typeof source === 'string') {
|
|
96
|
+
sax.parse(
|
|
97
|
+
normalize(source),
|
|
98
|
+
defaultNSMap,
|
|
99
|
+
entityMap
|
|
100
|
+
)
|
|
101
|
+
} else {
|
|
102
|
+
sax.errorHandler.error('invalid doc source')
|
|
40
103
|
}
|
|
41
104
|
return domBuilder.doc;
|
|
42
105
|
}
|
|
@@ -255,14 +318,5 @@ function appendElement (hander,node) {
|
|
|
255
318
|
}//appendChild and setAttributeNS are preformance key
|
|
256
319
|
|
|
257
320
|
exports.__DOMHandler = DOMHandler;
|
|
321
|
+
exports.normalizeLineEndings = normalizeLineEndings;
|
|
258
322
|
exports.DOMParser = DOMParser;
|
|
259
|
-
|
|
260
|
-
/**
|
|
261
|
-
* @deprecated Import/require from main entry point instead
|
|
262
|
-
*/
|
|
263
|
-
exports.DOMImplementation = dom.DOMImplementation;
|
|
264
|
-
|
|
265
|
-
/**
|
|
266
|
-
* @deprecated Import/require from main entry point instead
|
|
267
|
-
*/
|
|
268
|
-
exports.XMLSerializer = dom.XMLSerializer;
|
package/lib/dom.js
CHANGED
|
@@ -488,6 +488,20 @@ Node.prototype = {
|
|
|
488
488
|
hasAttributes:function(){
|
|
489
489
|
return this.attributes.length>0;
|
|
490
490
|
},
|
|
491
|
+
/**
|
|
492
|
+
* Look up the prefix associated to the given namespace URI, starting from this node.
|
|
493
|
+
* **The default namespace declarations are ignored by this method.**
|
|
494
|
+
* See Namespace Prefix Lookup for details on the algorithm used by this method.
|
|
495
|
+
*
|
|
496
|
+
* _Note: The implementation seems to be incomplete when compared to the algorithm described in the specs._
|
|
497
|
+
*
|
|
498
|
+
* @param {string | null} namespaceURI
|
|
499
|
+
* @returns {string | null}
|
|
500
|
+
* @see https://www.w3.org/TR/DOM-Level-3-Core/core.html#Node3-lookupNamespacePrefix
|
|
501
|
+
* @see https://www.w3.org/TR/DOM-Level-3-Core/namespaces-algorithms.html#lookupNamespacePrefixAlgo
|
|
502
|
+
* @see https://dom.spec.whatwg.org/#dom-node-lookupprefix
|
|
503
|
+
* @see https://github.com/xmldom/xmldom/issues/322
|
|
504
|
+
*/
|
|
491
505
|
lookupPrefix:function(namespaceURI){
|
|
492
506
|
var el = this;
|
|
493
507
|
while(el){
|
|
@@ -577,48 +591,67 @@ function _onRemoveAttribute(doc,el,newAttr,remove){
|
|
|
577
591
|
}
|
|
578
592
|
}
|
|
579
593
|
|
|
580
|
-
|
|
594
|
+
/**
|
|
595
|
+
* Updates `el.childNodes`, updating the indexed items and it's `length`.
|
|
596
|
+
* Passing `newChild` means it will be appended.
|
|
597
|
+
* Otherwise it's assumed that an item has been removed,
|
|
598
|
+
* and `el.firstNode` and it's `.nextSibling` are used
|
|
599
|
+
* to walk the current list of child nodes.
|
|
600
|
+
*
|
|
601
|
+
* @param {Document} doc
|
|
602
|
+
* @param {Node} el
|
|
603
|
+
* @param {Node} [newChild]
|
|
604
|
+
* @private
|
|
605
|
+
*/
|
|
606
|
+
function _onUpdateChild (doc, el, newChild) {
|
|
581
607
|
if(doc && doc._inc){
|
|
582
608
|
doc._inc++;
|
|
583
609
|
//update childNodes
|
|
584
610
|
var cs = el.childNodes;
|
|
585
|
-
if(newChild){
|
|
611
|
+
if (newChild) {
|
|
586
612
|
cs[cs.length++] = newChild;
|
|
587
|
-
}else{
|
|
588
|
-
//console.log(1)
|
|
613
|
+
} else {
|
|
589
614
|
var child = el.firstChild;
|
|
590
615
|
var i = 0;
|
|
591
|
-
while(child){
|
|
616
|
+
while (child) {
|
|
592
617
|
cs[i++] = child;
|
|
593
|
-
child =child.nextSibling;
|
|
618
|
+
child = child.nextSibling;
|
|
594
619
|
}
|
|
595
620
|
cs.length = i;
|
|
621
|
+
delete cs[cs.length];
|
|
596
622
|
}
|
|
597
623
|
}
|
|
598
624
|
}
|
|
599
625
|
|
|
600
626
|
/**
|
|
601
|
-
*
|
|
602
|
-
*
|
|
603
|
-
*
|
|
604
|
-
*
|
|
605
|
-
*
|
|
606
|
-
*
|
|
627
|
+
* Removes the connections between `parentNode` and `child`
|
|
628
|
+
* and any existing `child.previousSibling` or `child.nextSibling`.
|
|
629
|
+
*
|
|
630
|
+
* @see https://github.com/xmldom/xmldom/issues/135
|
|
631
|
+
* @see https://github.com/xmldom/xmldom/issues/145
|
|
632
|
+
*
|
|
633
|
+
* @param {Node} parentNode
|
|
634
|
+
* @param {Node} child
|
|
635
|
+
* @returns {Node} the child that was removed.
|
|
636
|
+
* @private
|
|
607
637
|
*/
|
|
608
|
-
function _removeChild(parentNode,child){
|
|
638
|
+
function _removeChild (parentNode, child) {
|
|
609
639
|
var previous = child.previousSibling;
|
|
610
640
|
var next = child.nextSibling;
|
|
611
|
-
if(previous){
|
|
641
|
+
if (previous) {
|
|
612
642
|
previous.nextSibling = next;
|
|
613
|
-
}else{
|
|
614
|
-
parentNode.firstChild = next
|
|
643
|
+
} else {
|
|
644
|
+
parentNode.firstChild = next;
|
|
615
645
|
}
|
|
616
|
-
if(next){
|
|
646
|
+
if (next) {
|
|
617
647
|
next.previousSibling = previous;
|
|
618
|
-
}else{
|
|
648
|
+
} else {
|
|
619
649
|
parentNode.lastChild = previous;
|
|
620
650
|
}
|
|
621
|
-
|
|
651
|
+
child.parentNode = null;
|
|
652
|
+
child.previousSibling = null;
|
|
653
|
+
child.nextSibling = null;
|
|
654
|
+
_onUpdateChild(parentNode.ownerDocument, parentNode);
|
|
622
655
|
return child;
|
|
623
656
|
}
|
|
624
657
|
/**
|
|
@@ -664,27 +697,35 @@ function _insertBefore(parentNode,newChild,nextChild){
|
|
|
664
697
|
}
|
|
665
698
|
return newChild;
|
|
666
699
|
}
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
700
|
+
|
|
701
|
+
/**
|
|
702
|
+
* Appends `newChild` to `parentNode`.
|
|
703
|
+
* If `newChild` is already connected to a `parentNode` it is first removed from it.
|
|
704
|
+
*
|
|
705
|
+
* @see https://github.com/xmldom/xmldom/issues/135
|
|
706
|
+
* @see https://github.com/xmldom/xmldom/issues/145
|
|
707
|
+
* @param {Node} parentNode
|
|
708
|
+
* @param {Node} newChild
|
|
709
|
+
* @returns {Node}
|
|
710
|
+
* @private
|
|
711
|
+
*/
|
|
712
|
+
function _appendSingleChild (parentNode, newChild) {
|
|
713
|
+
if (newChild.parentNode) {
|
|
714
|
+
newChild.parentNode.removeChild(newChild);
|
|
673
715
|
}
|
|
674
|
-
var pre = parentNode.lastChild;
|
|
675
716
|
newChild.parentNode = parentNode;
|
|
676
|
-
newChild.previousSibling =
|
|
717
|
+
newChild.previousSibling = parentNode.lastChild;
|
|
677
718
|
newChild.nextSibling = null;
|
|
678
|
-
if(
|
|
679
|
-
|
|
680
|
-
}else{
|
|
719
|
+
if (newChild.previousSibling) {
|
|
720
|
+
newChild.previousSibling.nextSibling = newChild;
|
|
721
|
+
} else {
|
|
681
722
|
parentNode.firstChild = newChild;
|
|
682
723
|
}
|
|
683
724
|
parentNode.lastChild = newChild;
|
|
684
|
-
_onUpdateChild(parentNode.ownerDocument,parentNode,newChild);
|
|
725
|
+
_onUpdateChild(parentNode.ownerDocument, parentNode, newChild);
|
|
685
726
|
return newChild;
|
|
686
|
-
//console.log("__aa",parentNode.lastChild.nextSibling == null)
|
|
687
727
|
}
|
|
728
|
+
|
|
688
729
|
Document.prototype = {
|
|
689
730
|
//implementation : null,
|
|
690
731
|
nodeName : '#document',
|
|
@@ -1137,12 +1178,18 @@ function needNamespaceDefine(node, isHTML, visibleNamespaces) {
|
|
|
1137
1178
|
}
|
|
1138
1179
|
/**
|
|
1139
1180
|
* Well-formed constraint: No < in Attribute Values
|
|
1140
|
-
* The replacement text of any entity referred to directly or indirectly
|
|
1141
|
-
*
|
|
1142
|
-
* @see https://www.w3.org/TR/
|
|
1181
|
+
* > The replacement text of any entity referred to directly or indirectly
|
|
1182
|
+
* > in an attribute value must not contain a <.
|
|
1183
|
+
* @see https://www.w3.org/TR/xml11/#CleanAttrVals
|
|
1184
|
+
* @see https://www.w3.org/TR/xml11/#NT-AttValue
|
|
1185
|
+
*
|
|
1186
|
+
* Literal whitespace other than space that appear in attribute values
|
|
1187
|
+
* are serialized as their entity references, so they will be preserved.
|
|
1188
|
+
* (In contrast to whitespace literals in the input which are normalized to spaces)
|
|
1189
|
+
* @see https://www.w3.org/TR/xml11/#AVNormalize
|
|
1143
1190
|
*/
|
|
1144
1191
|
function addSerializedAttribute(buf, qualifiedName, value) {
|
|
1145
|
-
buf.push(' ', qualifiedName, '="', value.replace(/[<&"]/g,_xmlEncoder), '"')
|
|
1192
|
+
buf.push(' ', qualifiedName, '="', value.replace(/[<&"\t\n\r]/g, _xmlEncoder), '"')
|
|
1146
1193
|
}
|
|
1147
1194
|
|
|
1148
1195
|
function serializeToString(node,buf,isHTML,nodeFilter,visibleNamespaces){
|
|
@@ -1175,12 +1222,23 @@ function serializeToString(node,buf,isHTML,nodeFilter,visibleNamespaces){
|
|
|
1175
1222
|
var prefixedNodeName = nodeName
|
|
1176
1223
|
if (!isHTML && !node.prefix && node.namespaceURI) {
|
|
1177
1224
|
var defaultNS
|
|
1225
|
+
// lookup current default ns from `xmlns` attribute
|
|
1178
1226
|
for (var ai = 0; ai < attrs.length; ai++) {
|
|
1179
1227
|
if (attrs.item(ai).name === 'xmlns') {
|
|
1180
1228
|
defaultNS = attrs.item(ai).value
|
|
1181
1229
|
break
|
|
1182
1230
|
}
|
|
1183
1231
|
}
|
|
1232
|
+
if (!defaultNS) {
|
|
1233
|
+
// lookup current default ns in visibleNamespaces
|
|
1234
|
+
for (var nsi = visibleNamespaces.length - 1; nsi >= 0; nsi--) {
|
|
1235
|
+
var namespace = visibleNamespaces[nsi]
|
|
1236
|
+
if (namespace.prefix === '' && namespace.namespace === node.namespaceURI) {
|
|
1237
|
+
defaultNS = namespace.namespace
|
|
1238
|
+
break
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1184
1242
|
if (defaultNS !== node.namespaceURI) {
|
|
1185
1243
|
for (var nsi = visibleNamespaces.length - 1; nsi >= 0; nsi--) {
|
|
1186
1244
|
var namespace = visibleNamespaces[nsi]
|
package/lib/sax.js
CHANGED
|
@@ -12,7 +12,7 @@ var tagNamePattern = new RegExp('^'+nameStartChar.source+nameChar.source+'*(?:\:
|
|
|
12
12
|
//S_TAG, S_ATTR, S_EQ, S_ATTR_NOQUOT_VALUE
|
|
13
13
|
//S_ATTR_SPACE, S_ATTR_END, S_TAG_SPACE, S_TAG_CLOSE
|
|
14
14
|
var S_TAG = 0;//tag name offerring
|
|
15
|
-
var S_ATTR = 1;//attr name offerring
|
|
15
|
+
var S_ATTR = 1;//attr name offerring
|
|
16
16
|
var S_ATTR_SPACE=2;//attr name end and space offer
|
|
17
17
|
var S_EQ = 3;//=space?
|
|
18
18
|
var S_ATTR_NOQUOT_VALUE = 4;//attr value(no quot value only)
|
|
@@ -36,7 +36,7 @@ ParseError.prototype = new Error();
|
|
|
36
36
|
ParseError.prototype.name = ParseError.name
|
|
37
37
|
|
|
38
38
|
function XMLReader(){
|
|
39
|
-
|
|
39
|
+
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
XMLReader.prototype = {
|
|
@@ -65,8 +65,8 @@ function parse(source,defaultNSMapCopy,entityMap,domBuilder,errorHandler){
|
|
|
65
65
|
}
|
|
66
66
|
function entityReplacer(a){
|
|
67
67
|
var k = a.slice(1,-1);
|
|
68
|
-
if(k
|
|
69
|
-
return entityMap[k];
|
|
68
|
+
if (Object.hasOwnProperty.call(entityMap, k)) {
|
|
69
|
+
return entityMap[k];
|
|
70
70
|
}else if(k.charAt(0) === '#'){
|
|
71
71
|
return fixedFromCharCode(parseInt(k.substr(1).replace('x','0x')))
|
|
72
72
|
}else{
|
|
@@ -95,7 +95,7 @@ function parse(source,defaultNSMapCopy,entityMap,domBuilder,errorHandler){
|
|
|
95
95
|
var lineEnd = 0;
|
|
96
96
|
var linePattern = /.*(?:\r\n?|\n)|.*$/g
|
|
97
97
|
var locator = domBuilder.locator;
|
|
98
|
-
|
|
98
|
+
|
|
99
99
|
var parseStack = [{currentNSMap:defaultNSMapCopy}]
|
|
100
100
|
var closeMap = {};
|
|
101
101
|
var start = 0;
|
|
@@ -120,7 +120,7 @@ function parse(source,defaultNSMapCopy,entityMap,domBuilder,errorHandler){
|
|
|
120
120
|
var tagName = source.substring(tagStart + 2, end).replace(/[ \t\n\r]+$/g, '');
|
|
121
121
|
var config = parseStack.pop();
|
|
122
122
|
if(end<0){
|
|
123
|
-
|
|
123
|
+
|
|
124
124
|
tagName = source.substring(tagStart+2).replace(/[\s<].*/,'');
|
|
125
125
|
errorHandler.error("end tag name: "+tagName+' is not complete:'+config.tagName);
|
|
126
126
|
end = tagStart+1+tagName.length;
|
|
@@ -145,7 +145,7 @@ function parse(source,defaultNSMapCopy,entityMap,domBuilder,errorHandler){
|
|
|
145
145
|
}else{
|
|
146
146
|
parseStack.push(config)
|
|
147
147
|
}
|
|
148
|
-
|
|
148
|
+
|
|
149
149
|
end++;
|
|
150
150
|
break;
|
|
151
151
|
// end elment
|
|
@@ -164,8 +164,8 @@ function parse(source,defaultNSMapCopy,entityMap,domBuilder,errorHandler){
|
|
|
164
164
|
//elStartEnd
|
|
165
165
|
var end = parseElementStartPart(source,tagStart,el,currentNSMap,entityReplacer,errorHandler);
|
|
166
166
|
var len = el.length;
|
|
167
|
-
|
|
168
|
-
|
|
167
|
+
|
|
168
|
+
|
|
169
169
|
if(!el.closed && fixSelfClosed(source,end,el.tagName,closeMap)){
|
|
170
170
|
el.closed = true;
|
|
171
171
|
if(!entityMap.nbsp){
|
|
@@ -230,8 +230,18 @@ function parseElementStartPart(source,start,el,currentNSMap,entityReplacer,error
|
|
|
230
230
|
* @param {number} startIndex
|
|
231
231
|
*/
|
|
232
232
|
function addAttribute(qname, value, startIndex) {
|
|
233
|
-
if (
|
|
234
|
-
|
|
233
|
+
if (el.attributeNames.hasOwnProperty(qname)) {
|
|
234
|
+
errorHandler.fatalError('Attribute ' + qname + ' redefined')
|
|
235
|
+
}
|
|
236
|
+
el.addValue(
|
|
237
|
+
qname,
|
|
238
|
+
// @see https://www.w3.org/TR/xml/#AVNormalize
|
|
239
|
+
// since the xmldom sax parser does not "interpret" DTD the following is not implemented:
|
|
240
|
+
// - recursive replacement of (DTD) entity references
|
|
241
|
+
// - trimming and collapsing multiple spaces into a single one for attributes that are not of type CDATA
|
|
242
|
+
value.replace(/[\t\n\r]/g, ' ').replace(/&#?\w+;/g, entityReplacer),
|
|
243
|
+
startIndex
|
|
244
|
+
)
|
|
235
245
|
}
|
|
236
246
|
var attrName;
|
|
237
247
|
var value;
|
|
@@ -262,7 +272,7 @@ function parseElementStartPart(source,start,el,currentNSMap,entityReplacer,error
|
|
|
262
272
|
start = p+1;
|
|
263
273
|
p = source.indexOf(c,start)
|
|
264
274
|
if(p>0){
|
|
265
|
-
value = source.slice(start,p)
|
|
275
|
+
value = source.slice(start, p);
|
|
266
276
|
addAttribute(attrName, value, start-1);
|
|
267
277
|
s = S_ATTR_END;
|
|
268
278
|
}else{
|
|
@@ -270,10 +280,8 @@ function parseElementStartPart(source,start,el,currentNSMap,entityReplacer,error
|
|
|
270
280
|
throw new Error('attribute value no end \''+c+'\' match');
|
|
271
281
|
}
|
|
272
282
|
}else if(s == S_ATTR_NOQUOT_VALUE){
|
|
273
|
-
value = source.slice(start,p)
|
|
274
|
-
//console.log(attrName,value,start,p)
|
|
283
|
+
value = source.slice(start, p);
|
|
275
284
|
addAttribute(attrName, value, start);
|
|
276
|
-
//console.dir(el)
|
|
277
285
|
errorHandler.warning('attribute "'+attrName+'" missed start quot('+c+')!!');
|
|
278
286
|
start = p+1;
|
|
279
287
|
s = S_ATTR_END
|
|
@@ -327,7 +335,7 @@ function parseElementStartPart(source,start,el,currentNSMap,entityReplacer,error
|
|
|
327
335
|
}
|
|
328
336
|
if(s == S_ATTR_NOQUOT_VALUE){
|
|
329
337
|
errorHandler.warning('attribute "'+value+'" missed quot(")!');
|
|
330
|
-
addAttribute(attrName, value
|
|
338
|
+
addAttribute(attrName, value, start)
|
|
331
339
|
}else{
|
|
332
340
|
if(!NAMESPACE.isHTML(currentNSMap['']) || !value.match(/^(?:disabled|checked|selected)$/i)){
|
|
333
341
|
errorHandler.warning('attribute "'+value+'" missed value!! "'+value+'" instead!!')
|
|
@@ -355,7 +363,7 @@ function parseElementStartPart(source,start,el,currentNSMap,entityReplacer,error
|
|
|
355
363
|
s = S_ATTR_SPACE;
|
|
356
364
|
break;
|
|
357
365
|
case S_ATTR_NOQUOT_VALUE:
|
|
358
|
-
var value = source.slice(start,p)
|
|
366
|
+
var value = source.slice(start, p);
|
|
359
367
|
errorHandler.warning('attribute "'+value+'" missed quot(")!!');
|
|
360
368
|
addAttribute(attrName, value, start)
|
|
361
369
|
case S_ATTR_END:
|
|
@@ -427,7 +435,7 @@ function appendElement(el,domBuilder,currentNSMap){
|
|
|
427
435
|
}
|
|
428
436
|
//can not set prefix,because prefix !== ''
|
|
429
437
|
a.localName = localName ;
|
|
430
|
-
//prefix == null for no ns prefix attribute
|
|
438
|
+
//prefix == null for no ns prefix attribute
|
|
431
439
|
if(nsPrefix !== false){//hack!!
|
|
432
440
|
if(localNSMap == null){
|
|
433
441
|
localNSMap = {}
|
|
@@ -437,7 +445,7 @@ function appendElement(el,domBuilder,currentNSMap){
|
|
|
437
445
|
}
|
|
438
446
|
currentNSMap[nsPrefix] = localNSMap[nsPrefix] = value;
|
|
439
447
|
a.uri = NAMESPACE.XMLNS
|
|
440
|
-
domBuilder.startPrefixMapping(nsPrefix, value)
|
|
448
|
+
domBuilder.startPrefixMapping(nsPrefix, value)
|
|
441
449
|
}
|
|
442
450
|
}
|
|
443
451
|
var i = el.length;
|
|
@@ -449,7 +457,7 @@ function appendElement(el,domBuilder,currentNSMap){
|
|
|
449
457
|
a.uri = NAMESPACE.XML;
|
|
450
458
|
}if(prefix !== 'xmlns'){
|
|
451
459
|
a.uri = currentNSMap[prefix || '']
|
|
452
|
-
|
|
460
|
+
|
|
453
461
|
//{console.log('###'+a.qName,domBuilder.locator.systemId+'',currentNSMap,a.uri)}
|
|
454
462
|
}
|
|
455
463
|
}
|
|
@@ -471,7 +479,7 @@ function appendElement(el,domBuilder,currentNSMap){
|
|
|
471
479
|
domBuilder.endElement(ns,localName,tagName);
|
|
472
480
|
if(localNSMap){
|
|
473
481
|
for(prefix in localNSMap){
|
|
474
|
-
domBuilder.endPrefixMapping(prefix)
|
|
482
|
+
domBuilder.endPrefixMapping(prefix)
|
|
475
483
|
}
|
|
476
484
|
}
|
|
477
485
|
}else{
|
|
@@ -498,7 +506,7 @@ function parseHtmlSpecialContent(source,elStartEnd,tagName,entityReplacer,domBui
|
|
|
498
506
|
domBuilder.characters(text,0,text.length);
|
|
499
507
|
return elEndStart;
|
|
500
508
|
//}
|
|
501
|
-
|
|
509
|
+
|
|
502
510
|
}
|
|
503
511
|
}
|
|
504
512
|
return elStartEnd+1;
|
|
@@ -515,7 +523,7 @@ function fixSelfClosed(source,elStartEnd,tagName,closeMap){
|
|
|
515
523
|
closeMap[tagName] =pos
|
|
516
524
|
}
|
|
517
525
|
return pos<elStartEnd;
|
|
518
|
-
//}
|
|
526
|
+
//}
|
|
519
527
|
}
|
|
520
528
|
function _copy(source,target){
|
|
521
529
|
for(var n in source){target[n] = source[n]}
|
|
@@ -543,11 +551,11 @@ function parseDCC(source,start,domBuilder,errorHandler){//sure start with '<!'
|
|
|
543
551
|
var end = source.indexOf(']]>',start+9);
|
|
544
552
|
domBuilder.startCDATA();
|
|
545
553
|
domBuilder.characters(source,start+9,end-start-9);
|
|
546
|
-
domBuilder.endCDATA()
|
|
554
|
+
domBuilder.endCDATA()
|
|
547
555
|
return end+3;
|
|
548
556
|
}
|
|
549
557
|
//<!DOCTYPE
|
|
550
|
-
//startDTD(java.lang.String name, java.lang.String publicId, java.lang.String systemId)
|
|
558
|
+
//startDTD(java.lang.String name, java.lang.String publicId, java.lang.String systemId)
|
|
551
559
|
var matchs = split(source,start);
|
|
552
560
|
var len = matchs.length;
|
|
553
561
|
if(len>1 && /!doctype/i.test(matchs[0][0])){
|
|
@@ -565,7 +573,7 @@ function parseDCC(source,start,domBuilder,errorHandler){//sure start with '<!'
|
|
|
565
573
|
var lastMatch = matchs[len-1]
|
|
566
574
|
domBuilder.startDTD(name, pubid, sysid);
|
|
567
575
|
domBuilder.endDTD();
|
|
568
|
-
|
|
576
|
+
|
|
569
577
|
return lastMatch.index+lastMatch[0].length
|
|
570
578
|
}
|
|
571
579
|
}
|
|
@@ -614,7 +622,7 @@ ElementAttributes.prototype = {
|
|
|
614
622
|
getValue:function(i){return this[i].value}
|
|
615
623
|
// ,getIndex:function(uri, localName)){
|
|
616
624
|
// if(localName){
|
|
617
|
-
//
|
|
625
|
+
//
|
|
618
626
|
// }else{
|
|
619
627
|
// var qName = uri
|
|
620
628
|
// }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xmldom/xmldom",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"description": "A pure JavaScript W3C standard-based (XML DOM Level 2 Core) DOMParser and XMLSerializer module.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"w3c",
|
|
@@ -23,35 +23,47 @@
|
|
|
23
23
|
"CHANGELOG.md",
|
|
24
24
|
"LICENSE",
|
|
25
25
|
"readme.md",
|
|
26
|
+
"SECURITY.md",
|
|
26
27
|
"index.d.ts",
|
|
27
28
|
"lib"
|
|
28
29
|
],
|
|
29
30
|
"scripts": {
|
|
30
31
|
"lint": "eslint lib test",
|
|
32
|
+
"changelog": "auto-changelog --unreleased-only",
|
|
31
33
|
"start": "nodemon --watch package.json --watch lib --watch test --exec 'npm --silent run test && npm --silent run lint'",
|
|
32
34
|
"stryker": "stryker run",
|
|
33
35
|
"stryker:dry-run": "stryker run -m '' --reporters progress",
|
|
34
|
-
"test": "jest"
|
|
36
|
+
"test": "jest",
|
|
37
|
+
"version": "./changelog-has-version.sh",
|
|
38
|
+
"release": "np --no-yarn"
|
|
35
39
|
},
|
|
36
40
|
"engines": {
|
|
37
41
|
"node": ">=10.0.0"
|
|
38
42
|
},
|
|
39
43
|
"dependencies": {},
|
|
40
44
|
"devDependencies": {
|
|
41
|
-
"@stryker-mutator/core": "
|
|
42
|
-
"
|
|
43
|
-
"eslint
|
|
44
|
-
"eslint-
|
|
45
|
-
"eslint-plugin-
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
45
|
+
"@stryker-mutator/core": "5.6.1",
|
|
46
|
+
"auto-changelog": "2.4.0",
|
|
47
|
+
"eslint": "8.9.0",
|
|
48
|
+
"eslint-config-prettier": "8.3.0",
|
|
49
|
+
"eslint-plugin-es5": "1.5.0",
|
|
50
|
+
"eslint-plugin-prettier": "4.0.0",
|
|
51
|
+
"get-stream": "6.0.1",
|
|
52
|
+
"jest": "27.5.1",
|
|
53
|
+
"nodemon": "2.0.15",
|
|
54
|
+
"np": "7.6.0",
|
|
55
|
+
"prettier": "2.5.1",
|
|
56
|
+
"xmltest": "1.5.0",
|
|
57
|
+
"yauzl": "2.10.0"
|
|
52
58
|
},
|
|
53
59
|
"bugs": {
|
|
54
60
|
"url": "https://github.com/xmldom/xmldom/issues"
|
|
55
61
|
},
|
|
56
|
-
"license": "MIT"
|
|
62
|
+
"license": "MIT",
|
|
63
|
+
"auto-changelog": {
|
|
64
|
+
"prepend": true,
|
|
65
|
+
"remote": "upstream",
|
|
66
|
+
"tagPrefix": "",
|
|
67
|
+
"template": "./auto-changelog.hbs"
|
|
68
|
+
}
|
|
57
69
|
}
|
package/readme.md
CHANGED
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
***Since version 0.7.0 this package is published to npm as [`@xmldom/xmldom`](https://www.npmjs.com/package/@xmldom/xmldom) and no longer as [`xmldom`](https://www.npmjs.com/package/xmldom), because [we are no longer able to publish `xmldom`](https://github.com/xmldom/xmldom/issues/271).***
|
|
4
4
|
*For better readability in the docs we will continue to talk about this library as "xmldom".*
|
|
5
5
|
|
|
6
|
-
[](LICENSE)
|
|
6
|
+
[](https://github.com/xmldom/xmldom/blob/master/LICENSE)
|
|
7
7
|
[](https://www.npmjs.com/package/@xmldom/xmldom)
|
|
8
|
+
[](https://snyk.io/advisor/npm-package/@xmldom/xmldom)
|
|
8
9
|
[](https://github.com/xmldom/xmldom/issues?q=is%3Aissue+is%3Aopen+label%3Abug)
|
|
9
10
|
[](https://github.com/xmldom/xmldom/issues?q=is%3Aissue+is%3Aopen+label%3Ahelp-wanted)
|
|
10
11
|
[](https://dashboard.stryker-mutator.io/reports/github.com/xmldom/xmldom/master)
|