@xmldom/xmldom 0.8.2 → 0.9.0-beta.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/lib/sax.js CHANGED
@@ -1,4 +1,10 @@
1
- var NAMESPACE = require("./conventions").NAMESPACE;
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
@@ -162,13 +169,21 @@ function parse(source,defaultNSMapCopy,entityMap,domBuilder,errorHandler){
162
169
  var el = new ElementAttributes();
163
170
  var currentNSMap = parseStack[parseStack.length-1].currentNSMap;
164
171
  //elStartEnd
165
- var end = parseElementStartPart(source,tagStart,el,currentNSMap,entityReplacer,errorHandler);
172
+ var end = parseElementStartPart(
173
+ source,
174
+ tagStart,
175
+ el,
176
+ currentNSMap,
177
+ entityReplacer,
178
+ errorHandler,
179
+ isHTML
180
+ )
166
181
  var len = el.length;
167
182
 
168
183
 
169
184
  if(!el.closed && fixSelfClosed(source,end,el.tagName,closeMap)){
170
185
  el.closed = true;
171
- if(!entityMap.nbsp){
186
+ if(!isHTML){
172
187
  errorHandler.warning('unclosed xml attribute');
173
188
  }
174
189
  }
@@ -191,7 +206,7 @@ function parse(source,defaultNSMapCopy,entityMap,domBuilder,errorHandler){
191
206
  }
192
207
  }
193
208
 
194
- if (NAMESPACE.isHTML(el.uri) && !el.closed) {
209
+ if (isHTML && !el.closed) {
195
210
  end = parseHtmlSpecialContent(source,end,el.tagName,entityReplacer,domBuilder)
196
211
  } else {
197
212
  end++;
@@ -222,7 +237,9 @@ function copyLocator(f,t){
222
237
  * @see #appendElement(source,elStartEnd,el,selfClosed,entityReplacer,domBuilder,parseStack);
223
238
  * @return end of the elementStartPart(end of elementEndPart for selfClosed el)
224
239
  */
225
- function parseElementStartPart(source,start,el,currentNSMap,entityReplacer,errorHandler){
240
+ function parseElementStartPart(
241
+ source,start,el,currentNSMap,entityReplacer,errorHandler, isHTML
242
+ ){
226
243
 
227
244
  /**
228
245
  * @param {string} qname
@@ -337,7 +354,7 @@ function parseElementStartPart(source,start,el,currentNSMap,entityReplacer,error
337
354
  errorHandler.warning('attribute "'+value+'" missed quot(")!');
338
355
  addAttribute(attrName, value, start)
339
356
  }else{
340
- if(!NAMESPACE.isHTML(currentNSMap['']) || !value.match(/^(?:disabled|checked|selected)$/i)){
357
+ if(!isHTML){
341
358
  errorHandler.warning('attribute "'+value+'" missed value!! "'+value+'" instead!!')
342
359
  }
343
360
  addAttribute(value, value, start)
@@ -385,7 +402,7 @@ function parseElementStartPart(source,start,el,currentNSMap,entityReplacer,error
385
402
  //case S_ATTR_NOQUOT_VALUE:void();break;
386
403
  case S_ATTR_SPACE:
387
404
  var tagName = el.tagName;
388
- if (!NAMESPACE.isHTML(currentNSMap['']) || !attrName.match(/^(?:disabled|checked|selected)$/i)) {
405
+ if (!isHTML) {
389
406
  errorHandler.warning('attribute "'+attrName+'" missed value!! "'+attrName+'" instead2!!')
390
407
  }
391
408
  addAttribute(attrName, attrName, start);
@@ -457,8 +474,6 @@ function appendElement(el,domBuilder,currentNSMap){
457
474
  a.uri = NAMESPACE.XML;
458
475
  }if(prefix !== 'xmlns'){
459
476
  a.uri = currentNSMap[prefix || '']
460
-
461
- //{console.log('###'+a.qName,domBuilder.locator.systemId+'',currentNSMap,a.uri)}
462
477
  }
463
478
  }
464
479
  }
@@ -490,24 +505,20 @@ function appendElement(el,domBuilder,currentNSMap){
490
505
  }
491
506
  }
492
507
  function parseHtmlSpecialContent(source,elStartEnd,tagName,entityReplacer,domBuilder){
493
- if(/^(?:script|textarea)$/i.test(tagName)){
508
+ // https://html.spec.whatwg.org/#raw-text-elements
509
+ // https://html.spec.whatwg.org/#escapable-raw-text-elements
510
+ // https://html.spec.whatwg.org/#cdata-rcdata-restrictions:raw-text-elements
511
+ // TODO: https://html.spec.whatwg.org/#cdata-rcdata-restrictions
512
+ var isEscapableRaw = isHTMLEscapableRawTextElement(tagName);
513
+ if(isEscapableRaw || isHTMLRawTextElement(tagName)){
494
514
  var elEndStart = source.indexOf('</'+tagName+'>',elStartEnd);
495
515
  var text = source.substring(elStartEnd+1,elEndStart);
496
- if(/[&<]/.test(text)){
497
- if(/^script$/i.test(tagName)){
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
516
+
517
+ if(isEscapableRaw){
505
518
  text = text.replace(/&#?\w+;/g,entityReplacer);
519
+ }
506
520
  domBuilder.characters(text,0,text.length);
507
521
  return elEndStart;
508
- //}
509
-
510
- }
511
522
  }
512
523
  return elStartEnd+1;
513
524
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xmldom/xmldom",
3
- "version": "0.8.2",
3
+ "version": "0.9.0-beta.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",
@@ -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.12.0",
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.0.0",
50
+ "eslint-plugin-prettier": "4.2.1",
51
51
  "get-stream": "6.0.1",
52
52
  "jest": "27.5.1",
53
- "nodemon": "2.0.15",
54
- "np": "7.6.1",
55
- "prettier": "2.6.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
  },