@xmldom/xmldom 0.8.2 → 0.9.0-beta.2
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 +59 -8
- package/index.d.ts +42 -40
- package/lib/conventions.js +183 -9
- package/lib/dom-parser.js +237 -52
- package/lib/dom.js +276 -89
- package/lib/entities.js +2 -0
- package/lib/index.js +2 -0
- package/lib/sax.js +49 -28
- package/package.json +6 -6
package/lib/sax.js
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
var conventions = require("./conventions");
|
|
4
|
+
var isHTMLRawTextElement = conventions.isHTMLRawTextElement;
|
|
5
|
+
var isHTMLEscapableRawTextElement = conventions.isHTMLEscapableRawTextElement;
|
|
6
|
+
var NAMESPACE = conventions.NAMESPACE;
|
|
7
|
+
var MIME_TYPE = conventions.MIME_TYPE;
|
|
2
8
|
|
|
3
9
|
//[4] NameStartChar ::= ":" | [A-Z] | "_" | [a-z] | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x2FF] | [#x370-#x37D] | [#x37F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]
|
|
4
10
|
//[4a] NameChar ::= NameStartChar | "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] | [#x203F-#x2040]
|
|
@@ -50,6 +56,7 @@ XMLReader.prototype = {
|
|
|
50
56
|
}
|
|
51
57
|
}
|
|
52
58
|
function parse(source,defaultNSMapCopy,entityMap,domBuilder,errorHandler){
|
|
59
|
+
var isHTML = MIME_TYPE.isHTML(domBuilder.mimeType);
|
|
53
60
|
function fixedFromCharCode(code) {
|
|
54
61
|
// String.prototype.fromCharCode does not supports
|
|
55
62
|
// > 2 bytes unicode chars directly
|
|
@@ -135,8 +142,10 @@ function parse(source,defaultNSMapCopy,entityMap,domBuilder,errorHandler){
|
|
|
135
142
|
if(endIgnoreCaseMach){
|
|
136
143
|
domBuilder.endElement(config.uri,config.localName,tagName);
|
|
137
144
|
if(localNSMap){
|
|
138
|
-
for(var prefix in localNSMap){
|
|
139
|
-
|
|
145
|
+
for (var prefix in localNSMap) {
|
|
146
|
+
if (Object.prototype.hasOwnProperty.call(localNSMap, prefix)) {
|
|
147
|
+
domBuilder.endPrefixMapping(prefix);
|
|
148
|
+
}
|
|
140
149
|
}
|
|
141
150
|
}
|
|
142
151
|
if(!endMatch){
|
|
@@ -162,13 +171,21 @@ function parse(source,defaultNSMapCopy,entityMap,domBuilder,errorHandler){
|
|
|
162
171
|
var el = new ElementAttributes();
|
|
163
172
|
var currentNSMap = parseStack[parseStack.length-1].currentNSMap;
|
|
164
173
|
//elStartEnd
|
|
165
|
-
var end = parseElementStartPart(
|
|
174
|
+
var end = parseElementStartPart(
|
|
175
|
+
source,
|
|
176
|
+
tagStart,
|
|
177
|
+
el,
|
|
178
|
+
currentNSMap,
|
|
179
|
+
entityReplacer,
|
|
180
|
+
errorHandler,
|
|
181
|
+
isHTML
|
|
182
|
+
)
|
|
166
183
|
var len = el.length;
|
|
167
184
|
|
|
168
185
|
|
|
169
186
|
if(!el.closed && fixSelfClosed(source,end,el.tagName,closeMap)){
|
|
170
187
|
el.closed = true;
|
|
171
|
-
if(!
|
|
188
|
+
if(!isHTML){
|
|
172
189
|
errorHandler.warning('unclosed xml attribute');
|
|
173
190
|
}
|
|
174
191
|
}
|
|
@@ -191,7 +208,7 @@ function parse(source,defaultNSMapCopy,entityMap,domBuilder,errorHandler){
|
|
|
191
208
|
}
|
|
192
209
|
}
|
|
193
210
|
|
|
194
|
-
if (
|
|
211
|
+
if (isHTML && !el.closed) {
|
|
195
212
|
end = parseHtmlSpecialContent(source,end,el.tagName,entityReplacer,domBuilder)
|
|
196
213
|
} else {
|
|
197
214
|
end++;
|
|
@@ -222,7 +239,9 @@ function copyLocator(f,t){
|
|
|
222
239
|
* @see #appendElement(source,elStartEnd,el,selfClosed,entityReplacer,domBuilder,parseStack);
|
|
223
240
|
* @return end of the elementStartPart(end of elementEndPart for selfClosed el)
|
|
224
241
|
*/
|
|
225
|
-
function parseElementStartPart(
|
|
242
|
+
function parseElementStartPart(
|
|
243
|
+
source,start,el,currentNSMap,entityReplacer,errorHandler, isHTML
|
|
244
|
+
){
|
|
226
245
|
|
|
227
246
|
/**
|
|
228
247
|
* @param {string} qname
|
|
@@ -337,7 +356,7 @@ function parseElementStartPart(source,start,el,currentNSMap,entityReplacer,error
|
|
|
337
356
|
errorHandler.warning('attribute "'+value+'" missed quot(")!');
|
|
338
357
|
addAttribute(attrName, value, start)
|
|
339
358
|
}else{
|
|
340
|
-
if(!
|
|
359
|
+
if(!isHTML){
|
|
341
360
|
errorHandler.warning('attribute "'+value+'" missed value!! "'+value+'" instead!!')
|
|
342
361
|
}
|
|
343
362
|
addAttribute(value, value, start)
|
|
@@ -385,7 +404,7 @@ function parseElementStartPart(source,start,el,currentNSMap,entityReplacer,error
|
|
|
385
404
|
//case S_ATTR_NOQUOT_VALUE:void();break;
|
|
386
405
|
case S_ATTR_SPACE:
|
|
387
406
|
var tagName = el.tagName;
|
|
388
|
-
if (!
|
|
407
|
+
if (!isHTML) {
|
|
389
408
|
errorHandler.warning('attribute "'+attrName+'" missed value!! "'+attrName+'" instead2!!')
|
|
390
409
|
}
|
|
391
410
|
addAttribute(attrName, attrName, start);
|
|
@@ -457,8 +476,6 @@ function appendElement(el,domBuilder,currentNSMap){
|
|
|
457
476
|
a.uri = NAMESPACE.XML;
|
|
458
477
|
}if(prefix !== 'xmlns'){
|
|
459
478
|
a.uri = currentNSMap[prefix || '']
|
|
460
|
-
|
|
461
|
-
//{console.log('###'+a.qName,domBuilder.locator.systemId+'',currentNSMap,a.uri)}
|
|
462
479
|
}
|
|
463
480
|
}
|
|
464
481
|
}
|
|
@@ -478,8 +495,10 @@ function appendElement(el,domBuilder,currentNSMap){
|
|
|
478
495
|
if(el.closed){
|
|
479
496
|
domBuilder.endElement(ns,localName,tagName);
|
|
480
497
|
if(localNSMap){
|
|
481
|
-
for(prefix in localNSMap){
|
|
482
|
-
|
|
498
|
+
for (prefix in localNSMap) {
|
|
499
|
+
if (Object.prototype.hasOwnProperty.call(localNSMap, prefix)) {
|
|
500
|
+
domBuilder.endPrefixMapping(prefix);
|
|
501
|
+
}
|
|
483
502
|
}
|
|
484
503
|
}
|
|
485
504
|
}else{
|
|
@@ -490,24 +509,20 @@ function appendElement(el,domBuilder,currentNSMap){
|
|
|
490
509
|
}
|
|
491
510
|
}
|
|
492
511
|
function parseHtmlSpecialContent(source,elStartEnd,tagName,entityReplacer,domBuilder){
|
|
493
|
-
|
|
512
|
+
// https://html.spec.whatwg.org/#raw-text-elements
|
|
513
|
+
// https://html.spec.whatwg.org/#escapable-raw-text-elements
|
|
514
|
+
// https://html.spec.whatwg.org/#cdata-rcdata-restrictions:raw-text-elements
|
|
515
|
+
// TODO: https://html.spec.whatwg.org/#cdata-rcdata-restrictions
|
|
516
|
+
var isEscapableRaw = isHTMLEscapableRawTextElement(tagName);
|
|
517
|
+
if(isEscapableRaw || isHTMLRawTextElement(tagName)){
|
|
494
518
|
var elEndStart = source.indexOf('</'+tagName+'>',elStartEnd);
|
|
495
519
|
var text = source.substring(elStartEnd+1,elEndStart);
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
//if(!/\]\]>/.test(text)){
|
|
499
|
-
//lexHandler.startCDATA();
|
|
500
|
-
domBuilder.characters(text,0,text.length);
|
|
501
|
-
//lexHandler.endCDATA();
|
|
502
|
-
return elEndStart;
|
|
503
|
-
//}
|
|
504
|
-
}//}else{//text area
|
|
520
|
+
|
|
521
|
+
if(isEscapableRaw){
|
|
505
522
|
text = text.replace(/&#?\w+;/g,entityReplacer);
|
|
523
|
+
}
|
|
506
524
|
domBuilder.characters(text,0,text.length);
|
|
507
525
|
return elEndStart;
|
|
508
|
-
//}
|
|
509
|
-
|
|
510
|
-
}
|
|
511
526
|
}
|
|
512
527
|
return elStartEnd+1;
|
|
513
528
|
}
|
|
@@ -525,9 +540,15 @@ function fixSelfClosed(source,elStartEnd,tagName,closeMap){
|
|
|
525
540
|
return pos<elStartEnd;
|
|
526
541
|
//}
|
|
527
542
|
}
|
|
528
|
-
|
|
529
|
-
|
|
543
|
+
|
|
544
|
+
function _copy (source, target) {
|
|
545
|
+
for (var n in source) {
|
|
546
|
+
if (Object.prototype.hasOwnProperty.call(source, n)) {
|
|
547
|
+
target[n] = source[n];
|
|
548
|
+
}
|
|
549
|
+
}
|
|
530
550
|
}
|
|
551
|
+
|
|
531
552
|
function parseDCC(source,start,domBuilder,errorHandler){//sure start with '<!'
|
|
532
553
|
var next= source.charAt(start+2)
|
|
533
554
|
switch(next){
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xmldom/xmldom",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0-beta.2",
|
|
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
|
},
|