@xmldom/xmldom 0.8.9 → 0.8.11

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.
Files changed (3) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/lib/dom.js +51 -6
  3. package/package.json +69 -69
package/CHANGELOG.md CHANGED
@@ -4,6 +4,24 @@ 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.11](https://github.com/xmldom/xmldom/compare/0.8.10...0.8.11)
8
+
9
+ ### Fixed
10
+
11
+ - update `ownerDocument` when moving nodes between documents
12
+
13
+ Thank you, [@shunkica](https://github.com/shunkica), for your contributions
14
+
15
+
16
+ ## [0.8.10](https://github.com/xmldom/xmldom/compare/0.8.9...0.8.10)
17
+
18
+ ### Fixed
19
+
20
+ - dom: prevent iteration over deleted items [`#514`](https://github.com/xmldom/xmldom/pull/514)/ [`#499`](https://github.com/xmldom/xmldom/issues/499)
21
+
22
+ Thank you, [@qtow](https://github.com/qtow), for your contributions
23
+
24
+
7
25
  ## [0.8.9](https://github.com/xmldom/xmldom/compare/0.8.8...0.8.9)
8
26
 
9
27
  ### Fixed
package/lib/dom.js CHANGED
@@ -169,7 +169,7 @@ NodeList.prototype = {
169
169
  * The node at the indexth position in the NodeList, or null if that is not a valid index.
170
170
  */
171
171
  item: function(index) {
172
- return this[index] || null;
172
+ return index >= 0 && index < this.length ? this[index] : null;
173
173
  },
174
174
  toString:function(isHTML,nodeFilter){
175
175
  for(var buf = [], i = 0;i<this.length;i++){
@@ -202,17 +202,23 @@ function LiveNodeList(node,refresh){
202
202
  }
203
203
  function _updateLiveList(list){
204
204
  var inc = list._node._inc || list._node.ownerDocument._inc;
205
- if(list._inc != inc){
205
+ if (list._inc !== inc) {
206
206
  var ls = list._refresh(list._node);
207
- //console.log(ls.length)
208
207
  __set__(list,'length',ls.length);
208
+ if (!list.$$length || ls.length < list.$$length) {
209
+ for (var i = ls.length; i in list; i++) {
210
+ if (Object.prototype.hasOwnProperty.call(list, i)) {
211
+ delete list[i];
212
+ }
213
+ }
214
+ }
209
215
  copy(ls,list);
210
216
  list._inc = inc;
211
217
  }
212
218
  }
213
219
  LiveNodeList.prototype.item = function(i){
214
220
  _updateLiveList(this);
215
- return this[i];
221
+ return this[i] || null;
216
222
  }
217
223
 
218
224
  _extends(LiveNodeList,NodeList);
@@ -974,6 +980,9 @@ function _insertBefore(parent, node, child, _inDocumentAssertion) {
974
980
  }
975
981
  do{
976
982
  newFirst.parentNode = parent;
983
+ // Update ownerDocument for each node being inserted
984
+ var targetDoc = parent.ownerDocument || parent;
985
+ _updateOwnerDocument(newFirst, targetDoc);
977
986
  }while(newFirst !== newLast && (newFirst= newFirst.nextSibling))
978
987
  _onUpdateChild(parent.ownerDocument||parent, parent);
979
988
  //console.log(parent.lastChild.nextSibling == null)
@@ -983,6 +992,37 @@ function _insertBefore(parent, node, child, _inDocumentAssertion) {
983
992
  return node;
984
993
  }
985
994
 
995
+ /**
996
+ * Recursively updates the ownerDocument property for a node and all its descendants
997
+ * @param {Node} node
998
+ * @param {Document} newOwnerDocument
999
+ * @private
1000
+ */
1001
+ function _updateOwnerDocument(node, newOwnerDocument) {
1002
+ if (node.ownerDocument === newOwnerDocument) {
1003
+ return;
1004
+ }
1005
+
1006
+ node.ownerDocument = newOwnerDocument;
1007
+
1008
+ // Update attributes if this is an element
1009
+ if (node.nodeType === ELEMENT_NODE && node.attributes) {
1010
+ for (var i = 0; i < node.attributes.length; i++) {
1011
+ var attr = node.attributes.item(i);
1012
+ if (attr) {
1013
+ attr.ownerDocument = newOwnerDocument;
1014
+ }
1015
+ }
1016
+ }
1017
+
1018
+ // Recursively update child nodes
1019
+ var child = node.firstChild;
1020
+ while (child) {
1021
+ _updateOwnerDocument(child, newOwnerDocument);
1022
+ child = child.nextSibling;
1023
+ }
1024
+ }
1025
+
986
1026
  /**
987
1027
  * Appends `newChild` to `parentNode`.
988
1028
  * If `newChild` is already connected to a `parentNode` it is first removed from it.
@@ -1008,6 +1048,11 @@ function _appendSingleChild (parentNode, newChild) {
1008
1048
  }
1009
1049
  parentNode.lastChild = newChild;
1010
1050
  _onUpdateChild(parentNode.ownerDocument, parentNode, newChild);
1051
+
1052
+ // Update ownerDocument for the new child and all its descendants
1053
+ var targetDoc = parentNode.ownerDocument || parentNode;
1054
+ _updateOwnerDocument(newChild, targetDoc);
1055
+
1011
1056
  return newChild;
1012
1057
  }
1013
1058
 
@@ -1036,7 +1081,7 @@ Document.prototype = {
1036
1081
  return newChild;
1037
1082
  }
1038
1083
  _insertBefore(this, newChild, refChild);
1039
- newChild.ownerDocument = this;
1084
+ _updateOwnerDocument(newChild, this);
1040
1085
  if (this.documentElement === null && newChild.nodeType === ELEMENT_NODE) {
1041
1086
  this.documentElement = newChild;
1042
1087
  }
@@ -1052,7 +1097,7 @@ Document.prototype = {
1052
1097
  replaceChild: function (newChild, oldChild) {
1053
1098
  //raises
1054
1099
  _insertBefore(this, newChild, oldChild, assertPreReplacementValidityInDocument);
1055
- newChild.ownerDocument = this;
1100
+ _updateOwnerDocument(newChild, this);
1056
1101
  if (oldChild) {
1057
1102
  this.removeChild(oldChild);
1058
1103
  }
package/package.json CHANGED
@@ -1,71 +1,71 @@
1
1
  {
2
- "name": "@xmldom/xmldom",
3
- "version": "0.8.9",
4
- "description": "A pure JavaScript W3C standard-based (XML DOM Level 2 Core) DOMParser and XMLSerializer module.",
5
- "keywords": [
6
- "w3c",
7
- "dom",
8
- "xml",
9
- "parser",
10
- "javascript",
11
- "DOMParser",
12
- "XMLSerializer",
13
- "ponyfill"
14
- ],
15
- "homepage": "https://github.com/xmldom/xmldom",
16
- "repository": {
17
- "type": "git",
18
- "url": "git://github.com/xmldom/xmldom.git"
19
- },
20
- "main": "lib/index.js",
21
- "types": "index.d.ts",
22
- "files": [
23
- "CHANGELOG.md",
24
- "LICENSE",
25
- "readme.md",
26
- "SECURITY.md",
27
- "index.d.ts",
28
- "lib"
29
- ],
30
- "scripts": {
31
- "lint": "eslint lib test",
32
- "format": "prettier --write test",
33
- "changelog": "auto-changelog --unreleased-only",
34
- "start": "nodemon --watch package.json --watch lib --watch test --exec 'npm --silent run test && npm --silent run lint'",
35
- "stryker": "stryker run",
36
- "stryker:dry-run": "stryker run -m '' --reporters progress",
37
- "test": "jest",
38
- "testrelease": "npm test && eslint lib",
39
- "version": "./changelog-has-version.sh",
40
- "release": "np --no-yarn --test-script testrelease --branch release-0.8.x patch"
41
- },
42
- "engines": {
43
- "node": ">=10.0.0"
44
- },
45
- "dependencies": {},
46
- "devDependencies": {
47
- "@stryker-mutator/core": "5.6.1",
48
- "auto-changelog": "2.4.0",
49
- "eslint": "8.25.0",
50
- "eslint-config-prettier": "8.5.0",
51
- "eslint-plugin-es5": "1.5.0",
52
- "eslint-plugin-prettier": "4.2.1",
53
- "get-stream": "6.0.1",
54
- "jest": "27.5.1",
55
- "nodemon": "2.0.20",
56
- "np": "7.6.2",
57
- "prettier": "2.7.1",
58
- "xmltest": "1.5.0",
59
- "yauzl": "2.10.0"
60
- },
61
- "bugs": {
62
- "url": "https://github.com/xmldom/xmldom/issues"
63
- },
64
- "license": "MIT",
65
- "auto-changelog": {
66
- "prepend": true,
67
- "remote": "upstream",
68
- "tagPrefix": "",
69
- "template": "./auto-changelog.hbs"
70
- }
2
+ "name": "@xmldom/xmldom",
3
+ "version": "0.8.11",
4
+ "description": "A pure JavaScript W3C standard-based (XML DOM Level 2 Core) DOMParser and XMLSerializer module.",
5
+ "keywords": [
6
+ "w3c",
7
+ "dom",
8
+ "xml",
9
+ "parser",
10
+ "javascript",
11
+ "DOMParser",
12
+ "XMLSerializer",
13
+ "ponyfill"
14
+ ],
15
+ "homepage": "https://github.com/xmldom/xmldom",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git://github.com/xmldom/xmldom.git"
19
+ },
20
+ "main": "lib/index.js",
21
+ "types": "index.d.ts",
22
+ "files": [
23
+ "CHANGELOG.md",
24
+ "LICENSE",
25
+ "readme.md",
26
+ "SECURITY.md",
27
+ "index.d.ts",
28
+ "lib"
29
+ ],
30
+ "scripts": {
31
+ "lint": "eslint lib test",
32
+ "format": "prettier --write test",
33
+ "changelog": "auto-changelog --unreleased-only",
34
+ "start": "nodemon --watch package.json --watch lib --watch test --exec 'npm --silent run test && npm --silent run lint'",
35
+ "stryker": "stryker run",
36
+ "stryker:dry-run": "stryker run -m '' --reporters progress",
37
+ "test": "jest",
38
+ "testrelease": "npm test && eslint lib",
39
+ "version": "./changelog-has-version.sh",
40
+ "release": "np --no-yarn --test-script testrelease --branch release-0.8.x patch"
41
+ },
42
+ "engines": {
43
+ "node": ">=10.0.0"
44
+ },
45
+ "dependencies": {},
46
+ "devDependencies": {
47
+ "@stryker-mutator/core": "5.6.1",
48
+ "auto-changelog": "2.4.0",
49
+ "eslint": "8.25.0",
50
+ "eslint-config-prettier": "8.5.0",
51
+ "eslint-plugin-es5": "1.5.0",
52
+ "eslint-plugin-prettier": "4.2.1",
53
+ "get-stream": "6.0.1",
54
+ "jest": "27.5.1",
55
+ "nodemon": "2.0.20",
56
+ "np": "9.2.0",
57
+ "prettier": "2.7.1",
58
+ "xmltest": "1.5.0",
59
+ "yauzl": "2.10.0"
60
+ },
61
+ "bugs": {
62
+ "url": "https://github.com/xmldom/xmldom/issues"
63
+ },
64
+ "license": "MIT",
65
+ "auto-changelog": {
66
+ "prepend": true,
67
+ "remote": "upstream",
68
+ "tagPrefix": "",
69
+ "template": "./auto-changelog.hbs"
70
+ }
71
71
  }