happy-dom 7.6.5 → 7.6.6
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.
Potentially problematic release.
This version of happy-dom might be problematic. Click here for more details.
@@ -32,68 +32,71 @@ class XMLParser {
|
|
32
32
|
let parentUnnestableTagName = null;
|
33
33
|
let lastTextIndex = 0;
|
34
34
|
let match;
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
const
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
const namespaceURI = tagName === 'svg'
|
44
|
-
? NamespaceURI_1.default.svg
|
45
|
-
: parent.namespaceURI || NamespaceURI_1.default.html;
|
46
|
-
const newElement = document.createElementNS(namespaceURI, tagName);
|
47
|
-
// Scripts are not allowed to be executed when they are parsed using innerHTML, outerHTML, replaceWith() etc.
|
48
|
-
// However, they are allowed to be executed when document.write() is used.
|
49
|
-
// See: https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement
|
50
|
-
if (tagName === 'script') {
|
51
|
-
newElement._evaluateScript = evaluateScripts;
|
52
|
-
}
|
53
|
-
// An assumption that the same rule should be applied for the HTMLLinkElement is made here.
|
54
|
-
if (tagName === 'link') {
|
55
|
-
newElement._evaluateCSS = evaluateScripts;
|
35
|
+
if (data !== null && data !== undefined) {
|
36
|
+
data = String(data);
|
37
|
+
while ((match = markupRegexp.exec(data))) {
|
38
|
+
const tagName = match[2].toLowerCase();
|
39
|
+
const isStartTag = !match[1];
|
40
|
+
if (parent && match.index !== lastTextIndex) {
|
41
|
+
const text = data.substring(lastTextIndex, match.index);
|
42
|
+
this.appendTextAndCommentNodes(document, parent, text);
|
56
43
|
}
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
44
|
+
if (isStartTag) {
|
45
|
+
const namespaceURI = tagName === 'svg'
|
46
|
+
? NamespaceURI_1.default.svg
|
47
|
+
: parent.namespaceURI || NamespaceURI_1.default.html;
|
48
|
+
const newElement = document.createElementNS(namespaceURI, tagName);
|
49
|
+
// Scripts are not allowed to be executed when they are parsed using innerHTML, outerHTML, replaceWith() etc.
|
50
|
+
// However, they are allowed to be executed when document.write() is used.
|
51
|
+
// See: https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement
|
52
|
+
if (tagName === 'script') {
|
53
|
+
newElement._evaluateScript = evaluateScripts;
|
64
54
|
}
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
55
|
+
// An assumption that the same rule should be applied for the HTMLLinkElement is made here.
|
56
|
+
if (tagName === 'link') {
|
57
|
+
newElement._evaluateCSS = evaluateScripts;
|
58
|
+
}
|
59
|
+
this.setAttributes(newElement, match[3]);
|
60
|
+
if (!match[4] && !VoidElements_1.default.includes(tagName)) {
|
61
|
+
// Some elements are not allowed to be nested (e.g. "<a><a></a></a>" is not allowed.).
|
62
|
+
// Therefore we will auto-close the tag.
|
63
|
+
if (parentUnnestableTagName === tagName) {
|
64
|
+
stack.pop();
|
65
|
+
parent = parent.parentNode || root;
|
66
|
+
}
|
67
|
+
parent = parent.appendChild(newElement);
|
68
|
+
parentUnnestableTagName = this.getUnnestableTagName(parent);
|
69
|
+
stack.push(parent);
|
70
|
+
}
|
71
|
+
else {
|
72
|
+
parent.appendChild(newElement);
|
73
|
+
}
|
74
|
+
lastTextIndex = markupRegexp.lastIndex;
|
75
|
+
// Tags which contain non-parsed content
|
76
|
+
// For example: <script> JavaScript should not be parsed
|
77
|
+
if (ChildLessElements_1.default.includes(tagName)) {
|
78
|
+
let childLessMatch = null;
|
79
|
+
while ((childLessMatch = markupRegexp.exec(data))) {
|
80
|
+
if (childLessMatch[2].toLowerCase() === tagName && childLessMatch[1]) {
|
81
|
+
markupRegexp.lastIndex -= childLessMatch[0].length;
|
82
|
+
break;
|
83
|
+
}
|
81
84
|
}
|
82
85
|
}
|
83
86
|
}
|
87
|
+
else {
|
88
|
+
stack.pop();
|
89
|
+
parent = stack[stack.length - 1] || root;
|
90
|
+
parentUnnestableTagName = this.getUnnestableTagName(parent);
|
91
|
+
lastTextIndex = markupRegexp.lastIndex;
|
92
|
+
}
|
84
93
|
}
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
lastTextIndex = markupRegexp.lastIndex;
|
94
|
+
// Text after last element
|
95
|
+
if ((!match && data.length > 0) || (match && lastTextIndex !== match.index)) {
|
96
|
+
const text = data.substring(lastTextIndex);
|
97
|
+
this.appendTextAndCommentNodes(document, parent || root, text);
|
90
98
|
}
|
91
99
|
}
|
92
|
-
// Text after last element
|
93
|
-
if ((!match && data.length > 0) || (match && lastTextIndex !== match.index)) {
|
94
|
-
const text = data.substring(lastTextIndex);
|
95
|
-
this.appendTextAndCommentNodes(document, parent || root, text);
|
96
|
-
}
|
97
100
|
return root;
|
98
101
|
}
|
99
102
|
/**
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"XMLParser.js","sourceRoot":"","sources":["../../src/xml-parser/XMLParser.ts"],"names":[],"mappings":";;;;;AAGA,0EAAkD;AAClD,sFAA8D;AAC9D,oFAA4D;AAC5D,2BAA4B;AAC5B,0EAAkD;AAOlD,MAAM,aAAa,GAAG,+CAA+C,CAAC;AACtE,MAAM,cAAc,GAAG,gCAAgC,CAAC;AACxD,MAAM,8BAA8B,GAAG,aAAa,CAAC;AACrD,MAAM,gBAAgB,GAAG,sDAAsD,CAAC;AAEhF;;GAEG;AACH,MAAqB,SAAS;IAC7B;;;;;;;OAOG;IACI,MAAM,CAAC,KAAK,CAClB,QAAmB,EACnB,IAAY,EACZ,eAAe,GAAG,KAAK;QAEvB,MAAM,IAAI,GAAG,QAAQ,CAAC,sBAAsB,EAAE,CAAC;QAC/C,MAAM,KAAK,GAAwC,CAAC,IAAI,CAAC,CAAC;QAC1D,MAAM,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AAE,CAAC,CAAC;oBAC7D,MAAM,IAAI,GAAG,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;oBACpE,MAAM,YAAY,GAAG,OAAO,CAAC,OAAO,KAAK,KAAK,IAAI,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;oBAClF,OAAO,CAAC,cAAc,CAAC,YAAY,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;iBAClD;aACD;YAED,2BAA2B;YAC3B,KAAK,MAAM,IAAI,IAAI,UAAU,CAAC,OAAO,CAAC,gBAAgB,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE;gBAC9E,IAAI,IAAI,EAAE;oBACT,OAAO,CAAC,cAAc,CAAC,IAAI,EAAE,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,YAAY,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC;iBACrF;aACD;SACD;IACF,CAAC;IAED;;;;;;OAMG;IACK,MAAM,CAAC,iBAAiB,CAAC,YAAoB,EAAE,IAAY;QAClE,IAAI,YAAY,KAAK,sBAAY,CAAC,GAAG,EAAE;YACtC,OAAO,IAAI,CAAC;SACZ;QACD,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC;IAC3B,CAAC;CACD;AAtOD,4BAsOC"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "happy-dom",
|
3
|
-
"version": "7.6.
|
3
|
+
"version": "7.6.6",
|
4
4
|
"license": "MIT",
|
5
5
|
"homepage": "https://github.com/capricorn86/happy-dom",
|
6
6
|
"repository": "https://github.com/capricorn86/happy-dom",
|
@@ -75,5 +75,5 @@
|
|
75
75
|
"ts-jest": "^27.1.3",
|
76
76
|
"typescript": "^4.6.2"
|
77
77
|
},
|
78
|
-
"gitHead": "
|
78
|
+
"gitHead": "e4072902f23440d68bd104027b65bf67685d4396"
|
79
79
|
}
|
@@ -42,76 +42,80 @@ export default class XMLParser {
|
|
42
42
|
let lastTextIndex = 0;
|
43
43
|
let match: RegExpExecArray;
|
44
44
|
|
45
|
-
|
46
|
-
|
47
|
-
const isStartTag = !match[1];
|
45
|
+
if (data !== null && data !== undefined) {
|
46
|
+
data = String(data);
|
48
47
|
|
49
|
-
|
50
|
-
const
|
51
|
-
|
52
|
-
}
|
53
|
-
|
54
|
-
if (isStartTag) {
|
55
|
-
const namespaceURI =
|
56
|
-
tagName === 'svg'
|
57
|
-
? NamespaceURI.svg
|
58
|
-
: (<IElement>parent).namespaceURI || NamespaceURI.html;
|
59
|
-
const newElement = document.createElementNS(namespaceURI, tagName);
|
60
|
-
|
61
|
-
// Scripts are not allowed to be executed when they are parsed using innerHTML, outerHTML, replaceWith() etc.
|
62
|
-
// However, they are allowed to be executed when document.write() is used.
|
63
|
-
// See: https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement
|
64
|
-
if (tagName === 'script') {
|
65
|
-
(<HTMLScriptElement>newElement)._evaluateScript = evaluateScripts;
|
66
|
-
}
|
48
|
+
while ((match = markupRegexp.exec(data))) {
|
49
|
+
const tagName = match[2].toLowerCase();
|
50
|
+
const isStartTag = !match[1];
|
67
51
|
|
68
|
-
|
69
|
-
|
70
|
-
(
|
52
|
+
if (parent && match.index !== lastTextIndex) {
|
53
|
+
const text = data.substring(lastTextIndex, match.index);
|
54
|
+
this.appendTextAndCommentNodes(document, parent, text);
|
71
55
|
}
|
72
56
|
|
73
|
-
|
57
|
+
if (isStartTag) {
|
58
|
+
const namespaceURI =
|
59
|
+
tagName === 'svg'
|
60
|
+
? NamespaceURI.svg
|
61
|
+
: (<IElement>parent).namespaceURI || NamespaceURI.html;
|
62
|
+
const newElement = document.createElementNS(namespaceURI, tagName);
|
63
|
+
|
64
|
+
// Scripts are not allowed to be executed when they are parsed using innerHTML, outerHTML, replaceWith() etc.
|
65
|
+
// However, they are allowed to be executed when document.write() is used.
|
66
|
+
// See: https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement
|
67
|
+
if (tagName === 'script') {
|
68
|
+
(<HTMLScriptElement>newElement)._evaluateScript = evaluateScripts;
|
69
|
+
}
|
74
70
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
if (parentUnnestableTagName === tagName) {
|
79
|
-
stack.pop();
|
80
|
-
parent = <Element>parent.parentNode || root;
|
71
|
+
// An assumption that the same rule should be applied for the HTMLLinkElement is made here.
|
72
|
+
if (tagName === 'link') {
|
73
|
+
(<HTMLLinkElement>newElement)._evaluateCSS = evaluateScripts;
|
81
74
|
}
|
82
75
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
76
|
+
this.setAttributes(newElement, match[3]);
|
77
|
+
|
78
|
+
if (!match[4] && !VoidElements.includes(tagName)) {
|
79
|
+
// Some elements are not allowed to be nested (e.g. "<a><a></a></a>" is not allowed.).
|
80
|
+
// Therefore we will auto-close the tag.
|
81
|
+
if (parentUnnestableTagName === tagName) {
|
82
|
+
stack.pop();
|
83
|
+
parent = <Element>parent.parentNode || root;
|
84
|
+
}
|
85
|
+
|
86
|
+
parent = <Element>parent.appendChild(newElement);
|
87
|
+
parentUnnestableTagName = this.getUnnestableTagName(parent);
|
88
|
+
stack.push(parent);
|
89
|
+
} else {
|
90
|
+
parent.appendChild(newElement);
|
91
|
+
}
|
92
|
+
lastTextIndex = markupRegexp.lastIndex;
|
93
|
+
|
94
|
+
// Tags which contain non-parsed content
|
95
|
+
// For example: <script> JavaScript should not be parsed
|
96
|
+
if (ChildLessElements.includes(tagName)) {
|
97
|
+
let childLessMatch = null;
|
98
|
+
while ((childLessMatch = markupRegexp.exec(data))) {
|
99
|
+
if (childLessMatch[2].toLowerCase() === tagName && childLessMatch[1]) {
|
100
|
+
markupRegexp.lastIndex -= childLessMatch[0].length;
|
101
|
+
break;
|
102
|
+
}
|
99
103
|
}
|
100
104
|
}
|
101
|
-
}
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
parentUnnestableTagName = this.getUnnestableTagName(parent);
|
105
|
+
} else {
|
106
|
+
stack.pop();
|
107
|
+
parent = stack[stack.length - 1] || root;
|
108
|
+
parentUnnestableTagName = this.getUnnestableTagName(parent);
|
106
109
|
|
107
|
-
|
110
|
+
lastTextIndex = markupRegexp.lastIndex;
|
111
|
+
}
|
108
112
|
}
|
109
|
-
}
|
110
113
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
114
|
+
// Text after last element
|
115
|
+
if ((!match && data.length > 0) || (match && lastTextIndex !== match.index)) {
|
116
|
+
const text = data.substring(lastTextIndex);
|
117
|
+
this.appendTextAndCommentNodes(document, parent || root, text);
|
118
|
+
}
|
115
119
|
}
|
116
120
|
|
117
121
|
return root;
|