@xmldom/xmldom 0.8.2 → 0.8.4
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 +29 -8
- package/lib/dom.js +217 -58
- package/lib/sax.js +16 -6
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,27 @@ 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.4](https://github.com/xmldom/xmldom/compare/0.8.3...0.8.4)
|
|
8
|
+
|
|
9
|
+
### Fixed
|
|
10
|
+
|
|
11
|
+
- Security: Prevent inserting DOM nodes when they are not well-formed [`CVE-2022-39353`](https://github.com/xmldom/xmldom/security/advisories/GHSA-crh6-fp67-6883)
|
|
12
|
+
In case such a DOM would be created, the part that is not well-formed will be transformed into text nodes, in which xml specific characters like `<` and `>` are encoded accordingly.
|
|
13
|
+
In the upcoming version 0.9.0 those text nodes will no longer be added and an error will be thrown instead.
|
|
14
|
+
This change can break your code, if you relied on this behavior, e.g. multiple root elements in the past. We consider it more important to align with the specs that we want to be aligned with, considering the potential security issues that might derive from people not being aware of the difference in behavior.
|
|
15
|
+
Related Spec: <https://dom.spec.whatwg.org/#concept-node-ensure-pre-insertion-validity>
|
|
16
|
+
|
|
17
|
+
Thank you, [@frumioj](https://github.com/frumioj), [@cjbarth](https://github.com/cjbarth), [@markgollnick](https://github.com/markgollnick) for your contributions
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
## [0.8.3](https://github.com/xmldom/xmldom/compare/0.8.3...0.8.2)
|
|
21
|
+
|
|
22
|
+
### Fixed
|
|
23
|
+
- Avoid iterating over prototype properties [`#437`](https://github.com/xmldom/xmldom/pull/437) / [`#436`](https://github.com/xmldom/xmldom/issues/436)
|
|
24
|
+
|
|
25
|
+
Thank you, [@Supraja9726](https://github.com/Supraja9726) for your contributions
|
|
26
|
+
|
|
27
|
+
|
|
7
28
|
## [0.8.2](https://github.com/xmldom/xmldom/compare/0.8.1...0.8.2)
|
|
8
29
|
|
|
9
30
|
### Fixed
|
|
@@ -59,7 +80,7 @@ Thank you [@marrus-sh](https://github.com/marrus-sh), [@victorandree](https://gi
|
|
|
59
80
|
### Fixes:
|
|
60
81
|
|
|
61
82
|
- Preserve default namespace when serializing [`#319`](https://github.com/xmldom/xmldom/issues/319) / [`#321`](https://github.com/xmldom/xmldom/pull/321)
|
|
62
|
-
Thank you [@lupestro](https://github.com/lupestro)
|
|
83
|
+
Thank you, [@lupestro](https://github.com/lupestro)
|
|
63
84
|
|
|
64
85
|
## 0.7.4
|
|
65
86
|
|
|
@@ -68,7 +89,7 @@ Thank you [@marrus-sh](https://github.com/marrus-sh), [@victorandree](https://gi
|
|
|
68
89
|
### Fixes:
|
|
69
90
|
|
|
70
91
|
- Restore ability to parse `__prototype__` attributes [`#315`](https://github.com/xmldom/xmldom/pull/315)
|
|
71
|
-
Thank you [@dsimpsonOMF](https://github.com/dsimpsonOMF)
|
|
92
|
+
Thank you, [@dsimpsonOMF](https://github.com/dsimpsonOMF)
|
|
72
93
|
|
|
73
94
|
## 0.7.3
|
|
74
95
|
|
|
@@ -78,7 +99,7 @@ Thank you [@marrus-sh](https://github.com/marrus-sh), [@victorandree](https://gi
|
|
|
78
99
|
|
|
79
100
|
- Add doctype when parsing from string [`#277`](https://github.com/xmldom/xmldom/issues/277) / [`#301`](https://github.com/xmldom/xmldom/pull/301)
|
|
80
101
|
- Correct typo in error message [`#294`](https://github.com/xmldom/xmldom/pull/294)
|
|
81
|
-
Thank you [@rrthomas](https://github.com/rrthomas)
|
|
102
|
+
Thank you, [@rrthomas](https://github.com/rrthomas)
|
|
82
103
|
|
|
83
104
|
### Refactor:
|
|
84
105
|
|
|
@@ -103,7 +124,7 @@ Thank you [@marrus-sh](https://github.com/marrus-sh), [@victorandree](https://gi
|
|
|
103
124
|
### Fixes:
|
|
104
125
|
|
|
105
126
|
- Types: Add index.d.ts to packaged files [`#288`](https://github.com/xmldom/xmldom/pull/288)
|
|
106
|
-
Thank you [@forty](https://github.com/forty)
|
|
127
|
+
Thank you, [@forty](https://github.com/forty)
|
|
107
128
|
|
|
108
129
|
## 0.7.1
|
|
109
130
|
|
|
@@ -112,7 +133,7 @@ Thank you [@marrus-sh](https://github.com/marrus-sh), [@victorandree](https://gi
|
|
|
112
133
|
### Fixes:
|
|
113
134
|
|
|
114
135
|
- Types: Copy types from DefinitelyTyped [`#283`](https://github.com/xmldom/xmldom/pull/283)
|
|
115
|
-
Thank you [@kachkaev](https://github.com/kachkaev)
|
|
136
|
+
Thank you, [@kachkaev](https://github.com/kachkaev)
|
|
116
137
|
|
|
117
138
|
### Chore:
|
|
118
139
|
- package.json: remove author, maintainers, etc. [`#279`](https://github.com/xmldom/xmldom/pull/279)
|
|
@@ -129,7 +150,7 @@ For more details look at [`#278`](https://github.com/xmldom/xmldom/pull/278#issu
|
|
|
129
150
|
### Fixes:
|
|
130
151
|
|
|
131
152
|
- Security: Misinterpretation of malicious XML input [`CVE-2021-32796`](https://github.com/xmldom/xmldom/security/advisories/GHSA-5fg8-2547-mr8q)
|
|
132
|
-
- Implement `Document.getElementsByClassName` as specified [`#213`](https://github.com/xmldom/xmldom/pull/213), thank you [@ChALkeR](https://github.com/ChALkeR)
|
|
153
|
+
- Implement `Document.getElementsByClassName` as specified [`#213`](https://github.com/xmldom/xmldom/pull/213), thank you, [@ChALkeR](https://github.com/ChALkeR)
|
|
133
154
|
- Inherit namespace prefix from parent when required [`#268`](https://github.com/xmldom/xmldom/pull/268)
|
|
134
155
|
- Handle whitespace in closing tags [`#267`](https://github.com/xmldom/xmldom/pull/267)
|
|
135
156
|
- Update `DOMImplementation` according to recent specs [`#210`](https://github.com/xmldom/xmldom/pull/210)
|
|
@@ -137,7 +158,7 @@ For more details look at [`#278`](https://github.com/xmldom/xmldom/pull/278#issu
|
|
|
137
158
|
- No longer serializes any namespaces with an empty URI [`#244`](https://github.com/xmldom/xmldom/pull/244)
|
|
138
159
|
(related to [`#168`](https://github.com/xmldom/xmldom/pull/168) released in 0.6.0)
|
|
139
160
|
BREAKING CHANGE: Only if you rely on ["unsetting" a namespace prefix](https://github.com/xmldom/xmldom/pull/168#issuecomment-886984994) by setting it to an empty string
|
|
140
|
-
- Set `localName` as part of `Document.createElement` [`#229`](https://github.com/xmldom/xmldom/pull/229), thank you [@rrthomas](https://github.com/rrthomas)
|
|
161
|
+
- Set `localName` as part of `Document.createElement` [`#229`](https://github.com/xmldom/xmldom/pull/229), thank you, [@rrthomas](https://github.com/rrthomas)
|
|
141
162
|
|
|
142
163
|
### CI
|
|
143
164
|
|
|
@@ -156,7 +177,7 @@ For more details look at [`#278`](https://github.com/xmldom/xmldom/pull/278#issu
|
|
|
156
177
|
|
|
157
178
|
- Stop serializing empty namespace values like `xmlns:ds=""` [`#168`](https://github.com/xmldom/xmldom/pull/168)
|
|
158
179
|
BREAKING CHANGE: If your code expected empty namespaces attributes to be serialized.
|
|
159
|
-
Thank you [@pdecat](https://github.com/pdecat) and [@FranckDepoortere](https://github.com/FranckDepoortere)
|
|
180
|
+
Thank you, [@pdecat](https://github.com/pdecat) and [@FranckDepoortere](https://github.com/FranckDepoortere)
|
|
160
181
|
- Escape `<` to `<` when serializing attribute values [`#198`](https://github.com/xmldom/xmldom/issues/198) / [`#199`](https://github.com/xmldom/xmldom/pull/199)
|
|
161
182
|
|
|
162
183
|
## 0.5.0
|
package/lib/dom.js
CHANGED
|
@@ -62,7 +62,9 @@ function arrayIncludes (list) {
|
|
|
62
62
|
|
|
63
63
|
function copy(src,dest){
|
|
64
64
|
for(var p in src){
|
|
65
|
-
|
|
65
|
+
if (Object.prototype.hasOwnProperty.call(src, p)) {
|
|
66
|
+
dest[p] = src[p];
|
|
67
|
+
}
|
|
66
68
|
}
|
|
67
69
|
}
|
|
68
70
|
|
|
@@ -156,14 +158,14 @@ NodeList.prototype = {
|
|
|
156
158
|
* The number of nodes in the list. The range of valid child node indices is 0 to length-1 inclusive.
|
|
157
159
|
* @standard level1
|
|
158
160
|
*/
|
|
159
|
-
length:0,
|
|
161
|
+
length:0,
|
|
160
162
|
/**
|
|
161
163
|
* Returns the indexth item in the collection. If index is greater than or equal to the number of nodes in the list, this returns null.
|
|
162
164
|
* @standard level1
|
|
163
|
-
* @param index unsigned long
|
|
165
|
+
* @param index unsigned long
|
|
164
166
|
* Index into the collection.
|
|
165
167
|
* @return Node
|
|
166
|
-
* The node at the indexth position in the NodeList, or null if that is not a valid index.
|
|
168
|
+
* The node at the indexth position in the NodeList, or null if that is not a valid index.
|
|
167
169
|
*/
|
|
168
170
|
item: function(index) {
|
|
169
171
|
return this[index] || null;
|
|
@@ -173,7 +175,31 @@ NodeList.prototype = {
|
|
|
173
175
|
serializeToString(this[i],buf,isHTML,nodeFilter);
|
|
174
176
|
}
|
|
175
177
|
return buf.join('');
|
|
176
|
-
}
|
|
178
|
+
},
|
|
179
|
+
/**
|
|
180
|
+
* @private
|
|
181
|
+
* @param {function (Node):boolean} predicate
|
|
182
|
+
* @returns {Node | undefined}
|
|
183
|
+
*/
|
|
184
|
+
find: function (predicate) {
|
|
185
|
+
return Array.prototype.find.call(this, predicate);
|
|
186
|
+
},
|
|
187
|
+
/**
|
|
188
|
+
* @private
|
|
189
|
+
* @param {function (Node):boolean} predicate
|
|
190
|
+
* @returns {Node[]}
|
|
191
|
+
*/
|
|
192
|
+
filter: function (predicate) {
|
|
193
|
+
return Array.prototype.filter.call(this, predicate);
|
|
194
|
+
},
|
|
195
|
+
/**
|
|
196
|
+
* @private
|
|
197
|
+
* @param {Node} item
|
|
198
|
+
* @returns {number}
|
|
199
|
+
*/
|
|
200
|
+
indexOf: function (item) {
|
|
201
|
+
return Array.prototype.indexOf.call(this, item);
|
|
202
|
+
},
|
|
177
203
|
};
|
|
178
204
|
|
|
179
205
|
function LiveNodeList(node,refresh){
|
|
@@ -207,7 +233,7 @@ _extends(LiveNodeList,NodeList);
|
|
|
207
233
|
* but this is simply to allow convenient enumeration of the contents of a NamedNodeMap,
|
|
208
234
|
* and does not imply that the DOM specifies an order to these Nodes.
|
|
209
235
|
* NamedNodeMap objects in the DOM are live.
|
|
210
|
-
* used for attributes or DocumentType entities
|
|
236
|
+
* used for attributes or DocumentType entities
|
|
211
237
|
*/
|
|
212
238
|
function NamedNodeMap() {
|
|
213
239
|
};
|
|
@@ -251,7 +277,7 @@ function _removeNamedNode(el,list,attr){
|
|
|
251
277
|
}
|
|
252
278
|
}
|
|
253
279
|
}else{
|
|
254
|
-
throw DOMException(NOT_FOUND_ERR,new Error(el.tagName+'@'+attr))
|
|
280
|
+
throw new DOMException(NOT_FOUND_ERR,new Error(el.tagName+'@'+attr))
|
|
255
281
|
}
|
|
256
282
|
}
|
|
257
283
|
NamedNodeMap.prototype = {
|
|
@@ -296,10 +322,10 @@ NamedNodeMap.prototype = {
|
|
|
296
322
|
var attr = this.getNamedItem(key);
|
|
297
323
|
_removeNamedNode(this._ownerElement,this,attr);
|
|
298
324
|
return attr;
|
|
299
|
-
|
|
300
|
-
|
|
325
|
+
|
|
326
|
+
|
|
301
327
|
},// raises: NOT_FOUND_ERR,NO_MODIFICATION_ALLOWED_ERR
|
|
302
|
-
|
|
328
|
+
|
|
303
329
|
//for level2
|
|
304
330
|
removeNamedItemNS:function(namespaceURI,localName){
|
|
305
331
|
var attr = this.getNamedItemNS(namespaceURI,localName);
|
|
@@ -445,10 +471,10 @@ Node.prototype = {
|
|
|
445
471
|
prefix : null,
|
|
446
472
|
localName : null,
|
|
447
473
|
// Modified in DOM Level 2:
|
|
448
|
-
insertBefore:function(newChild, refChild){//raises
|
|
474
|
+
insertBefore:function(newChild, refChild){//raises
|
|
449
475
|
return _insertBefore(this,newChild,refChild);
|
|
450
476
|
},
|
|
451
|
-
replaceChild:function(newChild, oldChild){//raises
|
|
477
|
+
replaceChild:function(newChild, oldChild){//raises
|
|
452
478
|
this.insertBefore(newChild,oldChild);
|
|
453
479
|
if(oldChild){
|
|
454
480
|
this.removeChild(oldChild);
|
|
@@ -509,9 +535,9 @@ Node.prototype = {
|
|
|
509
535
|
//console.dir(map)
|
|
510
536
|
if(map){
|
|
511
537
|
for(var n in map){
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
538
|
+
if (Object.prototype.hasOwnProperty.call(map, n) && map[n] === namespaceURI) {
|
|
539
|
+
return n;
|
|
540
|
+
}
|
|
515
541
|
}
|
|
516
542
|
}
|
|
517
543
|
el = el.nodeType == ATTRIBUTE_NODE?el.ownerDocument : el.parentNode;
|
|
@@ -525,7 +551,7 @@ Node.prototype = {
|
|
|
525
551
|
var map = el._nsMap;
|
|
526
552
|
//console.dir(map)
|
|
527
553
|
if(map){
|
|
528
|
-
if(prefix
|
|
554
|
+
if(Object.prototype.hasOwnProperty.call(map, prefix)){
|
|
529
555
|
return map[prefix] ;
|
|
530
556
|
}
|
|
531
557
|
}
|
|
@@ -654,48 +680,177 @@ function _removeChild (parentNode, child) {
|
|
|
654
680
|
_onUpdateChild(parentNode.ownerDocument, parentNode);
|
|
655
681
|
return child;
|
|
656
682
|
}
|
|
683
|
+
|
|
657
684
|
/**
|
|
658
|
-
*
|
|
685
|
+
* Returns `true` if `node` can be a parent for insertion.
|
|
686
|
+
* @param {Node} node
|
|
687
|
+
* @returns {boolean}
|
|
659
688
|
*/
|
|
660
|
-
function
|
|
661
|
-
|
|
689
|
+
function hasValidParentNodeType(node) {
|
|
690
|
+
return (
|
|
691
|
+
node &&
|
|
692
|
+
(node.nodeType === Node.DOCUMENT_NODE || node.nodeType === Node.DOCUMENT_FRAGMENT_NODE || node.nodeType === Node.ELEMENT_NODE)
|
|
693
|
+
);
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
/**
|
|
697
|
+
* Returns `true` if `node` can be inserted according to it's `nodeType`.
|
|
698
|
+
* @param {Node} node
|
|
699
|
+
* @returns {boolean}
|
|
700
|
+
*/
|
|
701
|
+
function hasInsertableNodeType(node) {
|
|
702
|
+
return (
|
|
703
|
+
node &&
|
|
704
|
+
(isElementNode(node) ||
|
|
705
|
+
isTextNode(node) ||
|
|
706
|
+
isDocTypeNode(node) ||
|
|
707
|
+
node.nodeType === Node.DOCUMENT_FRAGMENT_NODE ||
|
|
708
|
+
node.nodeType === Node.COMMENT_NODE ||
|
|
709
|
+
node.nodeType === Node.PROCESSING_INSTRUCTION_NODE)
|
|
710
|
+
);
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
/**
|
|
714
|
+
* Returns true if `node` is a DOCTYPE node
|
|
715
|
+
* @param {Node} node
|
|
716
|
+
* @returns {boolean}
|
|
717
|
+
*/
|
|
718
|
+
function isDocTypeNode(node) {
|
|
719
|
+
return node && node.nodeType === Node.DOCUMENT_TYPE_NODE;
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
/**
|
|
723
|
+
* Returns true if the node is an element
|
|
724
|
+
* @param {Node} node
|
|
725
|
+
* @returns {boolean}
|
|
726
|
+
*/
|
|
727
|
+
function isElementNode(node) {
|
|
728
|
+
return node && node.nodeType === Node.ELEMENT_NODE;
|
|
729
|
+
}
|
|
730
|
+
/**
|
|
731
|
+
* Returns true if `node` is a text node
|
|
732
|
+
* @param {Node} node
|
|
733
|
+
* @returns {boolean}
|
|
734
|
+
*/
|
|
735
|
+
function isTextNode(node) {
|
|
736
|
+
return node && node.nodeType === Node.TEXT_NODE;
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
/**
|
|
740
|
+
* Check if en element node can be inserted before `child`, or at the end if child is falsy,
|
|
741
|
+
* according to the presence and position of a doctype node on the same level.
|
|
742
|
+
*
|
|
743
|
+
* @param {Document} doc The document node
|
|
744
|
+
* @param {Node} child the node that would become the nextSibling if the element would be inserted
|
|
745
|
+
* @returns {boolean} `true` if an element can be inserted before child
|
|
746
|
+
* @private
|
|
747
|
+
* https://dom.spec.whatwg.org/#concept-node-ensure-pre-insertion-validity
|
|
748
|
+
*/
|
|
749
|
+
function isElementInsertionPossible(doc, child) {
|
|
750
|
+
var parentChildNodes = doc.childNodes || [];
|
|
751
|
+
if (parentChildNodes.find(isElementNode) || isDocTypeNode(child)) {
|
|
752
|
+
return false;
|
|
753
|
+
}
|
|
754
|
+
var docTypeNode = parentChildNodes.find(isDocTypeNode);
|
|
755
|
+
return !(child && docTypeNode && parentChildNodes.indexOf(docTypeNode) > parentChildNodes.indexOf(child));
|
|
756
|
+
}
|
|
757
|
+
/**
|
|
758
|
+
* @private
|
|
759
|
+
* @param {Node} parent the parent node to insert `node` into
|
|
760
|
+
* @param {Node} node the node to insert
|
|
761
|
+
* @param {Node=} child the node that should become the `nextSibling` of `node`
|
|
762
|
+
* @returns {Node}
|
|
763
|
+
* @throws DOMException for several node combinations that would create a DOM that is not well-formed.
|
|
764
|
+
* @throws DOMException if `child` is provided but is not a child of `parent`.
|
|
765
|
+
* @see https://dom.spec.whatwg.org/#concept-node-ensure-pre-insertion-validity
|
|
766
|
+
*/
|
|
767
|
+
function _insertBefore(parent, node, child) {
|
|
768
|
+
if (!hasValidParentNodeType(parent)) {
|
|
769
|
+
throw new DOMException(HIERARCHY_REQUEST_ERR, 'Unexpected parent node type ' + parent.nodeType);
|
|
770
|
+
}
|
|
771
|
+
if (child && child.parentNode !== parent) {
|
|
772
|
+
throw new DOMException(NOT_FOUND_ERR, 'child not in parent');
|
|
773
|
+
}
|
|
774
|
+
if (
|
|
775
|
+
!hasInsertableNodeType(node) ||
|
|
776
|
+
// the sax parser currently adds top level text nodes, this will be fixed in 0.9.0
|
|
777
|
+
// || (node.nodeType === Node.TEXT_NODE && parent.nodeType === Node.DOCUMENT_NODE)
|
|
778
|
+
(isDocTypeNode(node) && parent.nodeType !== Node.DOCUMENT_NODE)
|
|
779
|
+
) {
|
|
780
|
+
throw new DOMException(
|
|
781
|
+
HIERARCHY_REQUEST_ERR,
|
|
782
|
+
'Unexpected node type ' + node.nodeType + ' for parent node type ' + parent.nodeType
|
|
783
|
+
);
|
|
784
|
+
}
|
|
785
|
+
var parentChildNodes = parent.childNodes || [];
|
|
786
|
+
var nodeChildNodes = node.childNodes || [];
|
|
787
|
+
if (parent.nodeType === Node.DOCUMENT_NODE) {
|
|
788
|
+
if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {
|
|
789
|
+
let nodeChildElements = nodeChildNodes.filter(isElementNode);
|
|
790
|
+
if (nodeChildElements.length > 1 || nodeChildNodes.find(isTextNode)) {
|
|
791
|
+
throw new DOMException(HIERARCHY_REQUEST_ERR, 'More than one element or text in fragment');
|
|
792
|
+
}
|
|
793
|
+
if (nodeChildElements.length === 1 && !isElementInsertionPossible(parent, child)) {
|
|
794
|
+
throw new DOMException(HIERARCHY_REQUEST_ERR, 'Element in fragment can not be inserted before doctype');
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
if (isElementNode(node)) {
|
|
798
|
+
if (parentChildNodes.find(isElementNode) || !isElementInsertionPossible(parent, child)) {
|
|
799
|
+
throw new DOMException(HIERARCHY_REQUEST_ERR, 'Only one element can be added and only after doctype');
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
if (isDocTypeNode(node)) {
|
|
803
|
+
if (parentChildNodes.find(isDocTypeNode)) {
|
|
804
|
+
throw new DOMException(HIERARCHY_REQUEST_ERR, 'Only one doctype is allowed');
|
|
805
|
+
}
|
|
806
|
+
let parentElementChild = parentChildNodes.find(isElementNode);
|
|
807
|
+
if (child && parentChildNodes.indexOf(parentElementChild) < parentChildNodes.indexOf(child)) {
|
|
808
|
+
throw new DOMException(HIERARCHY_REQUEST_ERR, 'Doctype can only be inserted before an element');
|
|
809
|
+
}
|
|
810
|
+
if (!child && parentElementChild) {
|
|
811
|
+
throw new DOMException(HIERARCHY_REQUEST_ERR, 'Doctype can not be appended since element is present');
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
var cp = node.parentNode;
|
|
662
817
|
if(cp){
|
|
663
|
-
cp.removeChild(
|
|
818
|
+
cp.removeChild(node);//remove and update
|
|
664
819
|
}
|
|
665
|
-
if(
|
|
666
|
-
var newFirst =
|
|
820
|
+
if(node.nodeType === DOCUMENT_FRAGMENT_NODE){
|
|
821
|
+
var newFirst = node.firstChild;
|
|
667
822
|
if (newFirst == null) {
|
|
668
|
-
return
|
|
823
|
+
return node;
|
|
669
824
|
}
|
|
670
|
-
var newLast =
|
|
825
|
+
var newLast = node.lastChild;
|
|
671
826
|
}else{
|
|
672
|
-
newFirst = newLast =
|
|
827
|
+
newFirst = newLast = node;
|
|
673
828
|
}
|
|
674
|
-
var pre =
|
|
829
|
+
var pre = child ? child.previousSibling : parent.lastChild;
|
|
675
830
|
|
|
676
831
|
newFirst.previousSibling = pre;
|
|
677
|
-
newLast.nextSibling =
|
|
678
|
-
|
|
679
|
-
|
|
832
|
+
newLast.nextSibling = child;
|
|
833
|
+
|
|
834
|
+
|
|
680
835
|
if(pre){
|
|
681
836
|
pre.nextSibling = newFirst;
|
|
682
837
|
}else{
|
|
683
|
-
|
|
838
|
+
parent.firstChild = newFirst;
|
|
684
839
|
}
|
|
685
|
-
if(
|
|
686
|
-
|
|
840
|
+
if(child == null){
|
|
841
|
+
parent.lastChild = newLast;
|
|
687
842
|
}else{
|
|
688
|
-
|
|
843
|
+
child.previousSibling = newLast;
|
|
689
844
|
}
|
|
690
845
|
do{
|
|
691
|
-
newFirst.parentNode =
|
|
846
|
+
newFirst.parentNode = parent;
|
|
692
847
|
}while(newFirst !== newLast && (newFirst= newFirst.nextSibling))
|
|
693
|
-
_onUpdateChild(
|
|
694
|
-
//console.log(
|
|
695
|
-
if (
|
|
696
|
-
|
|
848
|
+
_onUpdateChild(parent.ownerDocument||parent, parent);
|
|
849
|
+
//console.log(parent.lastChild.nextSibling == null)
|
|
850
|
+
if (node.nodeType == DOCUMENT_FRAGMENT_NODE) {
|
|
851
|
+
node.firstChild = node.lastChild = null;
|
|
697
852
|
}
|
|
698
|
-
return
|
|
853
|
+
return node;
|
|
699
854
|
}
|
|
700
855
|
|
|
701
856
|
/**
|
|
@@ -750,11 +905,13 @@ Document.prototype = {
|
|
|
750
905
|
}
|
|
751
906
|
return newChild;
|
|
752
907
|
}
|
|
753
|
-
|
|
908
|
+
_insertBefore(this, newChild, refChild);
|
|
909
|
+
newChild.ownerDocument = this;
|
|
910
|
+
if (this.documentElement === null && newChild.nodeType === ELEMENT_NODE) {
|
|
754
911
|
this.documentElement = newChild;
|
|
755
912
|
}
|
|
756
913
|
|
|
757
|
-
return
|
|
914
|
+
return newChild;
|
|
758
915
|
},
|
|
759
916
|
removeChild : function(oldChild){
|
|
760
917
|
if(this.documentElement == oldChild){
|
|
@@ -948,7 +1105,7 @@ Element.prototype = {
|
|
|
948
1105
|
var attr = this.getAttributeNode(name)
|
|
949
1106
|
attr && this.removeAttributeNode(attr);
|
|
950
1107
|
},
|
|
951
|
-
|
|
1108
|
+
|
|
952
1109
|
//four real opeartion method
|
|
953
1110
|
appendChild:function(newChild){
|
|
954
1111
|
if(newChild.nodeType === DOCUMENT_FRAGMENT_NODE){
|
|
@@ -972,7 +1129,7 @@ Element.prototype = {
|
|
|
972
1129
|
var old = this.getAttributeNodeNS(namespaceURI, localName);
|
|
973
1130
|
old && this.removeAttributeNode(old);
|
|
974
1131
|
},
|
|
975
|
-
|
|
1132
|
+
|
|
976
1133
|
hasAttributeNS : function(namespaceURI, localName){
|
|
977
1134
|
return this.getAttributeNodeNS(namespaceURI, localName)!=null;
|
|
978
1135
|
},
|
|
@@ -988,7 +1145,7 @@ Element.prototype = {
|
|
|
988
1145
|
getAttributeNodeNS : function(namespaceURI, localName){
|
|
989
1146
|
return this.attributes.getNamedItemNS(namespaceURI, localName);
|
|
990
1147
|
},
|
|
991
|
-
|
|
1148
|
+
|
|
992
1149
|
getElementsByTagName : function(tagName){
|
|
993
1150
|
return new LiveNodeList(this,function(base){
|
|
994
1151
|
var ls = [];
|
|
@@ -1009,7 +1166,7 @@ Element.prototype = {
|
|
|
1009
1166
|
}
|
|
1010
1167
|
});
|
|
1011
1168
|
return ls;
|
|
1012
|
-
|
|
1169
|
+
|
|
1013
1170
|
});
|
|
1014
1171
|
}
|
|
1015
1172
|
};
|
|
@@ -1038,7 +1195,7 @@ CharacterData.prototype = {
|
|
|
1038
1195
|
},
|
|
1039
1196
|
insertData: function(offset,text) {
|
|
1040
1197
|
this.replaceData(offset,0,text);
|
|
1041
|
-
|
|
1198
|
+
|
|
1042
1199
|
},
|
|
1043
1200
|
appendChild:function(newChild){
|
|
1044
1201
|
throw new Error(ExceptionMessage[HIERARCHY_REQUEST_ERR])
|
|
@@ -1132,7 +1289,7 @@ function nodeSerializeToString(isHtml,nodeFilter){
|
|
|
1132
1289
|
var refNode = this.nodeType == 9 && this.documentElement || this;
|
|
1133
1290
|
var prefix = refNode.prefix;
|
|
1134
1291
|
var uri = refNode.namespaceURI;
|
|
1135
|
-
|
|
1292
|
+
|
|
1136
1293
|
if(uri && prefix == null){
|
|
1137
1294
|
//console.log(prefix)
|
|
1138
1295
|
var prefix = refNode.lookupPrefix(uri);
|
|
@@ -1165,8 +1322,8 @@ function needNamespaceDefine(node, isHTML, visibleNamespaces) {
|
|
|
1165
1322
|
if (prefix === "xml" && uri === NAMESPACE.XML || uri === NAMESPACE.XMLNS) {
|
|
1166
1323
|
return false;
|
|
1167
1324
|
}
|
|
1168
|
-
|
|
1169
|
-
var i = visibleNamespaces.length
|
|
1325
|
+
|
|
1326
|
+
var i = visibleNamespaces.length
|
|
1170
1327
|
while (i--) {
|
|
1171
1328
|
var ns = visibleNamespaces[i];
|
|
1172
1329
|
// get namespace prefix
|
|
@@ -1217,7 +1374,7 @@ function serializeToString(node,buf,isHTML,nodeFilter,visibleNamespaces){
|
|
|
1217
1374
|
var len = attrs.length;
|
|
1218
1375
|
var child = node.firstChild;
|
|
1219
1376
|
var nodeName = node.tagName;
|
|
1220
|
-
|
|
1377
|
+
|
|
1221
1378
|
isHTML = NAMESPACE.isHTML(node.namespaceURI) || isHTML
|
|
1222
1379
|
|
|
1223
1380
|
var prefixedNodeName = nodeName
|
|
@@ -1276,14 +1433,14 @@ function serializeToString(node,buf,isHTML,nodeFilter,visibleNamespaces){
|
|
|
1276
1433
|
serializeToString(attr,buf,isHTML,nodeFilter,visibleNamespaces);
|
|
1277
1434
|
}
|
|
1278
1435
|
|
|
1279
|
-
// add namespace for current node
|
|
1436
|
+
// add namespace for current node
|
|
1280
1437
|
if (nodeName === prefixedNodeName && needNamespaceDefine(node, isHTML, visibleNamespaces)) {
|
|
1281
1438
|
var prefix = node.prefix||'';
|
|
1282
1439
|
var uri = node.namespaceURI;
|
|
1283
1440
|
addSerializedAttribute(buf, prefix ? 'xmlns:' + prefix : "xmlns", uri);
|
|
1284
1441
|
visibleNamespaces.push({ prefix: prefix, namespace:uri });
|
|
1285
1442
|
}
|
|
1286
|
-
|
|
1443
|
+
|
|
1287
1444
|
if(child || isHTML && !/^(?:meta|link|img|br|hr|input)$/i.test(nodeName)){
|
|
1288
1445
|
buf.push('>');
|
|
1289
1446
|
//if is cdata child node
|
|
@@ -1424,11 +1581,13 @@ function importNode(doc,node,deep){
|
|
|
1424
1581
|
// attributes:1,childNodes:1,parentNode:1,documentElement:1,doctype,};
|
|
1425
1582
|
function cloneNode(doc,node,deep){
|
|
1426
1583
|
var node2 = new node.constructor();
|
|
1427
|
-
for(var n in node){
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
if(v !=
|
|
1431
|
-
node2[n]
|
|
1584
|
+
for (var n in node) {
|
|
1585
|
+
if (Object.prototype.hasOwnProperty.call(node, n)) {
|
|
1586
|
+
var v = node[n];
|
|
1587
|
+
if (typeof v != "object") {
|
|
1588
|
+
if (v != node2[n]) {
|
|
1589
|
+
node2[n] = v;
|
|
1590
|
+
}
|
|
1432
1591
|
}
|
|
1433
1592
|
}
|
|
1434
1593
|
}
|
|
@@ -1496,7 +1655,7 @@ try{
|
|
|
1496
1655
|
}
|
|
1497
1656
|
}
|
|
1498
1657
|
})
|
|
1499
|
-
|
|
1658
|
+
|
|
1500
1659
|
function getTextContent(node){
|
|
1501
1660
|
switch(node.nodeType){
|
|
1502
1661
|
case ELEMENT_NODE:
|
package/lib/sax.js
CHANGED
|
@@ -135,8 +135,10 @@ function parse(source,defaultNSMapCopy,entityMap,domBuilder,errorHandler){
|
|
|
135
135
|
if(endIgnoreCaseMach){
|
|
136
136
|
domBuilder.endElement(config.uri,config.localName,tagName);
|
|
137
137
|
if(localNSMap){
|
|
138
|
-
for(var prefix in localNSMap){
|
|
139
|
-
|
|
138
|
+
for (var prefix in localNSMap) {
|
|
139
|
+
if (Object.prototype.hasOwnProperty.call(localNSMap, prefix)) {
|
|
140
|
+
domBuilder.endPrefixMapping(prefix);
|
|
141
|
+
}
|
|
140
142
|
}
|
|
141
143
|
}
|
|
142
144
|
if(!endMatch){
|
|
@@ -478,8 +480,10 @@ function appendElement(el,domBuilder,currentNSMap){
|
|
|
478
480
|
if(el.closed){
|
|
479
481
|
domBuilder.endElement(ns,localName,tagName);
|
|
480
482
|
if(localNSMap){
|
|
481
|
-
for(prefix in localNSMap){
|
|
482
|
-
|
|
483
|
+
for (prefix in localNSMap) {
|
|
484
|
+
if (Object.prototype.hasOwnProperty.call(localNSMap, prefix)) {
|
|
485
|
+
domBuilder.endPrefixMapping(prefix);
|
|
486
|
+
}
|
|
483
487
|
}
|
|
484
488
|
}
|
|
485
489
|
}else{
|
|
@@ -525,9 +529,15 @@ function fixSelfClosed(source,elStartEnd,tagName,closeMap){
|
|
|
525
529
|
return pos<elStartEnd;
|
|
526
530
|
//}
|
|
527
531
|
}
|
|
528
|
-
|
|
529
|
-
|
|
532
|
+
|
|
533
|
+
function _copy (source, target) {
|
|
534
|
+
for (var n in source) {
|
|
535
|
+
if (Object.prototype.hasOwnProperty.call(source, n)) {
|
|
536
|
+
target[n] = source[n];
|
|
537
|
+
}
|
|
538
|
+
}
|
|
530
539
|
}
|
|
540
|
+
|
|
531
541
|
function parseDCC(source,start,domBuilder,errorHandler){//sure start with '<!'
|
|
532
542
|
var next= source.charAt(start+2)
|
|
533
543
|
switch(next){
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xmldom/xmldom",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.4",
|
|
4
4
|
"description": "A pure JavaScript W3C standard-based (XML DOM Level 2 Core) DOMParser and XMLSerializer module.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"w3c",
|
|
@@ -44,15 +44,15 @@
|
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@stryker-mutator/core": "5.6.1",
|
|
46
46
|
"auto-changelog": "2.4.0",
|
|
47
|
-
"eslint": "8.
|
|
47
|
+
"eslint": "8.25.0",
|
|
48
48
|
"eslint-config-prettier": "8.5.0",
|
|
49
49
|
"eslint-plugin-es5": "1.5.0",
|
|
50
|
-
"eslint-plugin-prettier": "4.
|
|
50
|
+
"eslint-plugin-prettier": "4.2.1",
|
|
51
51
|
"get-stream": "6.0.1",
|
|
52
52
|
"jest": "27.5.1",
|
|
53
|
-
"nodemon": "2.0.
|
|
54
|
-
"np": "7.6.
|
|
55
|
-
"prettier": "2.
|
|
53
|
+
"nodemon": "2.0.20",
|
|
54
|
+
"np": "7.6.2",
|
|
55
|
+
"prettier": "2.7.1",
|
|
56
56
|
"xmltest": "1.5.0",
|
|
57
57
|
"yauzl": "2.10.0"
|
|
58
58
|
},
|