@wavemaker/angular-codegen 11.15.5-rc.259 → 11.15.5-rc.262

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.
@@ -131194,11 +131194,22 @@ function requireConventions$1 () {
131194
131194
  XMLNS: 'http://www.w3.org/2000/xmlns/',
131195
131195
  });
131196
131196
 
131197
+ //[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]
131198
+ //[4a] NameChar ::= NameStartChar | "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] | [#x203F-#x2040]
131199
+ //[5] Name ::= NameStartChar (NameChar)*
131200
+ var nameStartChar = /[A-Z_a-z\xC0-\xD6\xD8-\xF6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]/;//\u10000-\uEFFFF
131201
+ var nameChar = new RegExp("[\\-\\.0-9"+nameStartChar.source.slice(1,-1)+"\\u00B7\\u0300-\\u036F\\u203F-\\u2040]");
131202
+ var tagNamePattern = new RegExp('^'+nameStartChar.source+nameChar.source+'*(?:\:'+nameStartChar.source+nameChar.source+'*)?$');
131203
+ //var tagNamePattern = /^[a-zA-Z_][\w\-\.]*(?:\:[a-zA-Z_][\w\-\.]*)?$/
131204
+
131197
131205
  conventions$1.assign = assign;
131198
131206
  conventions$1.find = find;
131199
131207
  conventions$1.freeze = freeze;
131200
131208
  conventions$1.MIME_TYPE = MIME_TYPE;
131201
131209
  conventions$1.NAMESPACE = NAMESPACE;
131210
+ conventions$1.nameStartChar = nameStartChar;
131211
+ conventions$1.nameChar = nameChar;
131212
+ conventions$1.tagNamePattern = tagNamePattern;
131202
131213
  return conventions$1;
131203
131214
  }
131204
131215
 
@@ -131211,6 +131222,7 @@ function requireDom$1 () {
131211
131222
 
131212
131223
  var find = conventions.find;
131213
131224
  var NAMESPACE = conventions.NAMESPACE;
131225
+ var tagNamePattern = conventions.tagNamePattern;
131214
131226
 
131215
131227
  /**
131216
131228
  * A prerequisite for `[].filter`, to drop elements that are empty
@@ -131442,6 +131454,13 @@ function requireDom$1 () {
131442
131454
  * used for attributes or DocumentType entities
131443
131455
  */
131444
131456
  function NamedNodeMap() {
131457
+ // nodeName -> Attr membership index; lets the parse-time de-duplication in
131458
+ // setNamedItem resolve an existing attribute in O(1) instead of scanning the
131459
+ // list, so building an element with M attributes costs O(M) rather than O(M^2).
131460
+ // The numbered entries and length remain the sole authority for attribute order.
131461
+ // Object.create(null) so an attribute named __proto__ or constructor is an
131462
+ // ordinary key.
131463
+ this._nameIndex = Object.create(null);
131445
131464
  }
131446
131465
  function _findNodeIndex(list,node){
131447
131466
  var i = list.length;
@@ -131450,12 +131469,27 @@ function requireDom$1 () {
131450
131469
  }
131451
131470
  }
131452
131471
 
131472
+ function _nnmIndexAdd(list, attr) {
131473
+ list._nameIndex[attr.nodeName] = attr;
131474
+ }
131475
+ function _nnmIndexRemove(list, attr) {
131476
+ // Only drop the entry if it still points at this attribute; a replacement with
131477
+ // a different nodeName may already have re-keyed it.
131478
+ if (list._nameIndex[attr.nodeName] === attr) {
131479
+ delete list._nameIndex[attr.nodeName];
131480
+ }
131481
+ }
131482
+
131453
131483
  function _addNamedNode(el,list,newAttr,oldAttr){
131454
131484
  if(oldAttr){
131455
131485
  list[_findNodeIndex(list,oldAttr)] = newAttr;
131486
+ // oldAttr leaves the list; drop its index entry (its nodeName may differ
131487
+ // from newAttr's when the replacement came via setNamedItemNS).
131488
+ _nnmIndexRemove(list, oldAttr);
131456
131489
  }else {
131457
131490
  list[list.length++] = newAttr;
131458
131491
  }
131492
+ _nnmIndexAdd(list, newAttr);
131459
131493
  if(el){
131460
131494
  newAttr.ownerElement = el;
131461
131495
  var doc = el.ownerDocument;
@@ -131474,6 +131508,7 @@ function requireDom$1 () {
131474
131508
  list[i] = list[++i];
131475
131509
  }
131476
131510
  list.length = lastIndex;
131511
+ _nnmIndexRemove(list, attr);
131477
131512
  if(el){
131478
131513
  var doc = el.ownerDocument;
131479
131514
  if(doc){
@@ -131507,7 +131542,11 @@ function requireDom$1 () {
131507
131542
  if(el && el!=this._ownerElement){
131508
131543
  throw new DOMException(INUSE_ATTRIBUTE_ERR);
131509
131544
  }
131510
- var oldAttr = this.getNamedItem(attr.nodeName);
131545
+ // Resolve any existing attribute with the same nodeName through the O(1)
131546
+ // membership index rather than an O(M) scan — this is the parse-dedup hot
131547
+ // path (setAttributeNode per attribute during parse). Absent -> undefined,
131548
+ // matching getNamedItem's contract.
131549
+ var oldAttr = this._nameIndex[attr.nodeName];
131511
131550
  _addNamedNode(this._ownerElement,this,attr,oldAttr);
131512
131551
  return oldAttr;
131513
131552
  },
@@ -131740,9 +131779,38 @@ function requireDom$1 () {
131740
131779
  while (child) {
131741
131780
  var next = child.nextSibling;
131742
131781
  if (next !== null && next.nodeType === TEXT_NODE && child.nodeType === TEXT_NODE) {
131743
- node.removeChild(next);
131744
- child.appendData(next.data);
131745
- // Do not advance child: re-check new nextSibling for another text run
131782
+ // Merge the whole run of adjacent text nodes at once: gather the
131783
+ // following text siblings' data, unlink them in a single pass, and
131784
+ // re-index the child list a single time. Per-sibling `removeChild`
131785
+ // (each an O(K) re-index) plus per-sibling `appendData` (each an O(K)
131786
+ // string rebuild) is O(K^2) over a long run of single-character text
131787
+ // nodes; this keeps it O(K). The first text node of the run survives
131788
+ // and carries the concatenated data, preserving node identity and
131789
+ // locator semantics.
131790
+ var tail = [];
131791
+ var sibling = next;
131792
+ while (sibling !== null && sibling.nodeType === TEXT_NODE) {
131793
+ tail.push(sibling.data);
131794
+ sibling = sibling.nextSibling;
131795
+ }
131796
+ // `sibling` is now the first non-text node after the run, or null.
131797
+ var removed = child.nextSibling;
131798
+ while (removed !== sibling) {
131799
+ var following = removed.nextSibling;
131800
+ removed.parentNode = null;
131801
+ removed.previousSibling = null;
131802
+ removed.nextSibling = null;
131803
+ removed = following;
131804
+ }
131805
+ child.nextSibling = sibling;
131806
+ if (sibling !== null) {
131807
+ sibling.previousSibling = child;
131808
+ } else {
131809
+ node.lastChild = child;
131810
+ }
131811
+ child.appendData(tail.join('')); // single O(K) string rebuild
131812
+ _onUpdateChild(node.ownerDocument, node); // single O(K) re-index
131813
+ child = sibling;
131746
131814
  } else {
131747
131815
  child = next;
131748
131816
  }
@@ -132553,8 +132621,10 @@ function requireDom$1 () {
132553
132621
  * - it does not do any input validation on the arguments and doesn't throw "InvalidCharacterError".
132554
132622
  *
132555
132623
  * Note: When the resulting document is serialized with `requireWellFormed: true`, the
132556
- * serializer throws with code `INVALID_STATE_ERR` if `.data` contains `?>` (W3C DOM Parsing
132557
- * §3.2.1.7). Without that option the data is emitted verbatim.
132624
+ * serializer throws with code `INVALID_STATE_ERR` if `.target` is not a valid XML `NCName`
132625
+ * (a `Name` with no colon) or is an ASCII case-insensitive match for `"xml"`, or if `.data`
132626
+ * contains `?>` (W3C DOM Parsing §3.2.1.7). Without that option the target and data are
132627
+ * emitted verbatim.
132558
132628
  *
132559
132629
  * @param {string} target
132560
132630
  * @param {string} data
@@ -132579,7 +132649,27 @@ function requireDom$1 () {
132579
132649
  node.specified = true;
132580
132650
  return node;
132581
132651
  },
132652
+ /**
132653
+ * Creates an EntityReference object, serialized as `&name;`.
132654
+ *
132655
+ * The `name` is validated against the XML `Name` production at creation time; an invalid name
132656
+ * throws a `DOMException` with code `INVALID_CHARACTER_ERR`. When the resulting node is
132657
+ * serialized with `requireWellFormed: true`, the serializer re-validates `nodeName` and throws
132658
+ * a `DOMException` with code `INVALID_STATE_ERR` if a later `nodeName` mutation made it invalid;
132659
+ * without that option the name is emitted verbatim.
132660
+ *
132661
+ * Note: xmldom does not expand entities — the parser resolves entity references inline and never
132662
+ * constructs `EntityReference` nodes, so this method is the only producer.
132663
+ *
132664
+ * @param {string} name The name of the entity to reference.
132665
+ * @returns {EntityReference}
132666
+ * @throws {DOMException} With code `INVALID_CHARACTER_ERR` when `name` is not a valid XML `Name`.
132667
+ * @see https://www.w3.org/TR/DOM-Level-3-Core/core.html#ID-392B75AE
132668
+ */
132582
132669
  createEntityReference : function(name){
132670
+ if (!tagNamePattern.test(name)) {
132671
+ throw new DOMException(INVALID_CHARACTER_ERR, 'not a valid xml name "' + name + '"');
132672
+ }
132583
132673
  var node = new EntityReference();
132584
132674
  node.ownerDocument = this;
132585
132675
  node.nodeName = name;
@@ -132791,15 +132881,16 @@ function requireDom$1 () {
132791
132881
  /**
132792
132882
  * Represents a DocumentType node (the `<!DOCTYPE ...>` declaration).
132793
132883
  *
132794
- * `publicId`, `systemId`, and `internalSubset` are plain own-property assignments.
132884
+ * `name`, `publicId`, `systemId`, and `internalSubset` are plain own-property assignments.
132795
132885
  * xmldom does not enforce the `readonly` constraint declared by the WHATWG DOM spec —
132796
132886
  * direct property writes succeed silently. Values are serialized verbatim when
132797
132887
  * `requireWellFormed` is false (the default). When the serializer is invoked with
132798
132888
  * `requireWellFormed: true` (via the 4th-parameter options object), it validates each
132799
- * field and throws `DOMException` with code `INVALID_STATE_ERR` on invalid values.
132889
+ * field — including `name`, which is checked against the XML `Name` production — and throws
132890
+ * `DOMException` with code `INVALID_STATE_ERR` on invalid values.
132800
132891
  *
132801
132892
  * @class
132802
- * @see https://developer.mozilla.org/en-US/docs/Web/API/DocumentType MDN
132893
+ * @see https://developer.mozilla.org/docs/Web/API/DocumentType MDN
132803
132894
  */
132804
132895
  function DocumentType() {
132805
132896
  } DocumentType.prototype.nodeType = DOCUMENT_TYPE_NODE;
@@ -132813,6 +132904,20 @@ function requireDom$1 () {
132813
132904
  } Entity.prototype.nodeType = ENTITY_NODE;
132814
132905
  _extends(Entity,Node);
132815
132906
 
132907
+ /**
132908
+ * Represents an EntityReference node, serialized as `&nodeName;`.
132909
+ *
132910
+ * `nodeName` is the referenced entity's name, stored verbatim. When serialized with
132911
+ * `requireWellFormed: true`, the serializer validates `nodeName` against the XML `Name` production
132912
+ * and throws a `DOMException` with code `INVALID_STATE_ERR` if it does not match; without that
132913
+ * option the name is emitted verbatim between `&` and `;`.
132914
+ *
132915
+ * Note: xmldom does not expand entities — the parser resolves entity references inline and never
132916
+ * constructs `EntityReference` nodes, so the only producer is `Document.createEntityReference`.
132917
+ *
132918
+ * @class
132919
+ * @see https://www.w3.org/TR/xml/#NT-Name
132920
+ */
132816
132921
  function EntityReference() {
132817
132922
  } EntityReference.prototype.nodeType = ENTITY_REFERENCE_NODE;
132818
132923
  _extends(EntityReference,Node);
@@ -132850,14 +132955,20 @@ function requireDom$1 () {
132850
132955
  * @returns {string}
132851
132956
  * @throws {DOMException}
132852
132957
  * With code `INVALID_STATE_ERR` when `requireWellFormed` is `true` and:
132958
+ * - an Element's qualified name (including any namespace prefix) is not a valid XML QName,
132959
+ * - an attribute's qualified name (including a synthesized `xmlns:` namespace declaration) is
132960
+ * not a valid XML QName,
132853
132961
  * - a CDATASection node's data contains `"]]>"`,
132854
132962
  * - a Comment node's data contains `"-->"` (bare `"--"` does not throw on this branch),
132855
- * - a ProcessingInstruction's data contains `"?>"`,
132963
+ * - a ProcessingInstruction's target is not a valid XML `NCName` (a `Name` with no colon) or is
132964
+ * an ASCII case-insensitive match for `"xml"`, or its data contains `"?>"`,
132965
+ * - a DocumentType's `name` is not a valid XML `Name` (XML 1.0 production [5]),
132856
132966
  * - a DocumentType's `publicId` is non-empty and does not match the XML `PubidLiteral`
132857
132967
  * production,
132858
132968
  * - a DocumentType's `systemId` is non-empty and does not match the XML `SystemLiteral`
132859
- * production, or
132860
- * - a DocumentType's `internalSubset` contains `"]>"`.
132969
+ * production,
132970
+ * - a DocumentType's `internalSubset` contains `"]>"`, or
132971
+ * - an EntityReference's `nodeName` is not a valid XML `Name` (XML 1.0 production [5]).
132861
132972
  * Note: xmldom does not enforce `readonly` on DocumentType fields — direct property
132862
132973
  * writes succeed and are covered by the serializer-level checks above.
132863
132974
  * @see https://html.spec.whatwg.org/#dom-xmlserializer-serializetostring
@@ -132931,7 +133042,10 @@ function requireDom$1 () {
132931
133042
  * @see https://www.w3.org/TR/xml11/#AVNormalize
132932
133043
  * @see https://w3c.github.io/DOM-Parsing/#serializing-an-element-s-attributes
132933
133044
  */
132934
- function addSerializedAttribute(buf, qualifiedName, value) {
133045
+ function addSerializedAttribute(buf, qualifiedName, value, requireWellFormed) {
133046
+ if (requireWellFormed && !tagNamePattern.test(qualifiedName)) {
133047
+ throw new DOMException(INVALID_STATE_ERR, 'The attribute name "' + qualifiedName + '" is not a valid XML QName');
133048
+ }
132935
133049
  buf.push(' ', qualifiedName, '="', value.replace(/[<>&"\t\n\r]/g, _xmlEncoder), '"');
132936
133050
  }
132937
133051
 
@@ -132997,6 +133111,9 @@ function requireDom$1 () {
132997
133111
  }
132998
133112
  }
132999
133113
 
133114
+ if (requireWellFormed && !tagNamePattern.test(prefixedNodeName)) {
133115
+ throw new DOMException(INVALID_STATE_ERR, 'The element name "' + prefixedNodeName + '" is not a valid XML QName');
133116
+ }
133000
133117
  buf.push('<', prefixedNodeName);
133001
133118
 
133002
133119
  // Build a fresh namespace snapshot for this element's children.
@@ -133016,7 +133133,7 @@ function requireDom$1 () {
133016
133133
  if (needNamespaceDefine(attr, html, childNs)) {
133017
133134
  var attrPrefix = attr.prefix || '';
133018
133135
  var uri = attr.namespaceURI;
133019
- addSerializedAttribute(buf, attrPrefix ? 'xmlns:' + attrPrefix : 'xmlns', uri);
133136
+ addSerializedAttribute(buf, attrPrefix ? 'xmlns:' + attrPrefix : 'xmlns', uri, requireWellFormed);
133020
133137
  childNs.push({ prefix: attrPrefix, namespace: uri });
133021
133138
  }
133022
133139
  // Apply nodeFilter and serialize the attribute.
@@ -133025,7 +133142,7 @@ function requireDom$1 () {
133025
133142
  if (typeof filteredAttr === 'string') {
133026
133143
  buf.push(filteredAttr);
133027
133144
  } else {
133028
- addSerializedAttribute(buf, filteredAttr.name, filteredAttr.value);
133145
+ addSerializedAttribute(buf, filteredAttr.name, filteredAttr.value, requireWellFormed);
133029
133146
  }
133030
133147
  }
133031
133148
  }
@@ -133034,7 +133151,7 @@ function requireDom$1 () {
133034
133151
  if (nodeName === prefixedNodeName && needNamespaceDefine(n, html, childNs)) {
133035
133152
  var nodePrefix = n.prefix || '';
133036
133153
  var uri = n.namespaceURI;
133037
- addSerializedAttribute(buf, nodePrefix ? 'xmlns:' + nodePrefix : 'xmlns', uri);
133154
+ addSerializedAttribute(buf, nodePrefix ? 'xmlns:' + nodePrefix : 'xmlns', uri, requireWellFormed);
133038
133155
  childNs.push({ prefix: nodePrefix, namespace: uri });
133039
133156
  }
133040
133157
 
@@ -133067,7 +133184,7 @@ function requireDom$1 () {
133067
133184
  return { ns: ns.slice(), isHTML: html, tag: null };
133068
133185
 
133069
133186
  case ATTRIBUTE_NODE:
133070
- addSerializedAttribute(buf, n.name, n.value);
133187
+ addSerializedAttribute(buf, n.name, n.value, requireWellFormed);
133071
133188
  return null;
133072
133189
 
133073
133190
  case TEXT_NODE:
@@ -133106,6 +133223,9 @@ function requireDom$1 () {
133106
133223
 
133107
133224
  case DOCUMENT_TYPE_NODE:
133108
133225
  if (requireWellFormed) {
133226
+ if (!tagNamePattern.test(n.name)) {
133227
+ throw new DOMException(INVALID_STATE_ERR, 'The doctype name "' + n.name + '" is not a valid XML Name');
133228
+ }
133109
133229
  if (n.publicId && !/^("[\x20\r\na-zA-Z0-9\-()+,.\/:=?;!*#@$_%']*"|'[\x20\r\na-zA-Z0-9\-()+,.\/:=?;!*#@$_%'"]*')$/.test(n.publicId)) {
133110
133230
  throw new DOMException(INVALID_STATE_ERR, 'DocumentType publicId is not a valid PubidLiteral');
133111
133231
  }
@@ -133137,13 +133257,27 @@ function requireDom$1 () {
133137
133257
  return null;
133138
133258
 
133139
133259
  case PROCESSING_INSTRUCTION_NODE:
133140
- if (requireWellFormed && n.data.indexOf('?>') !== -1) {
133141
- throw new DOMException(INVALID_STATE_ERR, 'The ProcessingInstruction data contains "?>"');
133260
+ if (requireWellFormed) {
133261
+ if (!tagNamePattern.test(n.target) || n.target.indexOf(':') !== -1 || n.target.toLowerCase() === 'xml') {
133262
+ throw new DOMException(
133263
+ INVALID_STATE_ERR,
133264
+ 'The processing instruction target "' + n.target + '" is not a valid XML NCName or is reserved'
133265
+ );
133266
+ }
133267
+ if (n.data.indexOf('?>') !== -1) {
133268
+ throw new DOMException(INVALID_STATE_ERR, 'The ProcessingInstruction data contains "?>"');
133269
+ }
133142
133270
  }
133143
133271
  buf.push('<?', n.target, ' ', n.data, '?>');
133144
133272
  return null;
133145
133273
 
133146
133274
  case ENTITY_REFERENCE_NODE:
133275
+ if (requireWellFormed && !tagNamePattern.test(n.nodeName)) {
133276
+ throw new DOMException(
133277
+ INVALID_STATE_ERR,
133278
+ 'The entity reference name "' + n.nodeName + '" is not a valid XML Name'
133279
+ );
133280
+ }
133147
133281
  buf.push('&', n.nodeName, ';');
133148
133282
  return null;
133149
133283
 
@@ -135524,14 +135658,8 @@ function requireSax$1 () {
135524
135658
  if (hasRequiredSax$1) return sax$1;
135525
135659
  hasRequiredSax$1 = 1;
135526
135660
  var NAMESPACE = requireConventions$1().NAMESPACE;
135661
+ var tagNamePattern = requireConventions$1().tagNamePattern;
135527
135662
 
135528
- //[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]
135529
- //[4a] NameChar ::= NameStartChar | "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] | [#x203F-#x2040]
135530
- //[5] Name ::= NameStartChar (NameChar)*
135531
- var nameStartChar = /[A-Z_a-z\xC0-\xD6\xD8-\xF6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]/;//\u10000-\uEFFFF
135532
- var nameChar = new RegExp("[\\-\\.0-9"+nameStartChar.source.slice(1,-1)+"\\u00B7\\u0300-\\u036F\\u203F-\\u2040]");
135533
- var tagNamePattern = new RegExp('^'+nameStartChar.source+nameChar.source+'*(?:\:'+nameStartChar.source+nameChar.source+'*)?$');
135534
- //var tagNamePattern = /^[a-zA-Z_][\w\-\.]*(?:\:[a-zA-Z_][\w\-\.]*)?$/
135535
135663
  //var handlers = 'resolveEntity,getExternalSubset,characters,endDocument,endElement,endPrefixMapping,ignorableWhitespace,processingInstruction,setDocumentLocator,skippedEntity,startDocument,startElement,startPrefixMapping,notationDecl,unparsedEntityDecl,error,fatalError,warning,attributeDecl,elementDecl,externalEntityDecl,internalEntityDecl,comment,endCDATA,endDTD,endEntity,startCDATA,startDTD,startEntity'.split(',')
135536
135664
 
135537
135665
  //S_TAG, S_ATTR, S_EQ, S_ATTR_NOQUOT_VALUE
@@ -135642,7 +135770,13 @@ function requireSax$1 () {
135642
135770
  switch(source.charAt(tagStart+1)){
135643
135771
  case '/':
135644
135772
  var end = source.indexOf('>',tagStart+3);
135645
- var tagName = source.substring(tagStart + 2, end).replace(/[ \t\n\r]+$/g, '');
135773
+ // Anchored trailing-whitespace trim. The former `/[ \t\n\r]+$/g` backtracked
135774
+ // quadratically on a name shaped `whitespace-run + non-whitespace char`
135775
+ // (an end tag `</ … x>`): from every start position it extended `[ws]+`
135776
+ // to the end and then failed the `$` anchor. This anchored form matches the
135777
+ // whole string once and captures everything up to the last non-whitespace
135778
+ // character, so it trims in linear time with byte-identical output.
135779
+ var tagName = source.substring(tagStart + 2, end).replace(/^([\s\S]*?[^ \t\n\r])?[ \t\n\r]*$/, '$1');
135646
135780
  var config = parseStack.pop();
135647
135781
  if(end<0){
135648
135782
 
@@ -135653,6 +135787,14 @@ function requireSax$1 () {
135653
135787
  tagName = tagName.replace(/[\s<].*/,'');
135654
135788
  errorHandler.error("end tag name: "+tagName+' maybe not complete');
135655
135789
  end = tagStart+1+tagName.length;
135790
+ }else if(/[ \t\n\r]/.test(tagName) && tagNamePattern.test(tagName.split(/[ \t\n\r]/)[0])){
135791
+ // The XML `ETag` production is `'</' Name S? '>'`: only optional whitespace may follow
135792
+ // the `Name`. A valid `Name` followed by whitespace and non-whitespace residue (e.g.
135793
+ // `</a\nbogus>` or `</a bogus>`) is not well-formed, but historically it was silently
135794
+ // accepted (the malformed end tag ignored, the residue dropped, the element left on the
135795
+ // stack). Report it as a recoverable `error` (which a custom errorHandler may escalate to
135796
+ // fatal) while keeping the existing recovery so the parsed DOM stays byte-identical.
135797
+ errorHandler.error('end tag name is followed by whitespace and trailing content: "'+tagName+'"');
135656
135798
  }
135657
135799
  var localNSMap = config.localNSMap;
135658
135800
  var endMatch = config.tagName == tagName;
@@ -135776,6 +135918,15 @@ function requireSax$1 () {
135776
135918
  var s = S_TAG;//status
135777
135919
  while(true){
135778
135920
  var c = source.charAt(p);
135921
+ if (s === S_TAG && c === '<') {
135922
+ // A `<` can never occur inside a tag name. Without this guard the scan runs
135923
+ // on to the next `>` (or EOF) before the tag name is rejected, so a document
135924
+ // with many `<` inside a malformed tag makes each one-character recovery step
135925
+ // re-scan to the distant `>` — O(n^2). Stopping at the `<` keeps each recovery
135926
+ // step bounded. The candidate scanned so far is reported raw, consistent with
135927
+ // the sibling invalid-tag-name throw below.
135928
+ throw new Error('unexpected < in tag name: ' + source.slice(start, p));
135929
+ }
135779
135930
  switch(c){
135780
135931
  case '=':
135781
135932
  if(s === S_ATTR){//attrName
@@ -135968,9 +136119,13 @@ function requireSax$1 () {
135968
136119
  if(nsPrefix !== false){//hack!!
135969
136120
  if(localNSMap == null){
135970
136121
  localNSMap = {};
135971
- //console.log(currentNSMap,0)
135972
- _copy(currentNSMap,currentNSMap={});
135973
- //console.log(currentNSMap,1)
136122
+ // Derive the child scope's namespace map by prototype-chain inheritance
136123
+ // instead of a flat copy: lookups inherit ancestor prefixes transparently,
136124
+ // so a document nesting N scopes retains O(N) map entries rather than
136125
+ // sum(1..N) = O(N^2). localNSMap stays a flat own-only record of the
136126
+ // prefixes declared at THIS element, so own-property enumeration
136127
+ // (endPrefixMapping below) still reports only local declarations.
136128
+ currentNSMap = Object.create(currentNSMap);
135974
136129
  }
135975
136130
  currentNSMap[nsPrefix] = localNSMap[nsPrefix] = value;
135976
136131
  a.uri = NAMESPACE.XMLNS;
@@ -188242,11 +188397,22 @@ function requireConventions () {
188242
188397
  XMLNS: 'http://www.w3.org/2000/xmlns/',
188243
188398
  });
188244
188399
 
188400
+ //[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]
188401
+ //[4a] NameChar ::= NameStartChar | "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] | [#x203F-#x2040]
188402
+ //[5] Name ::= NameStartChar (NameChar)*
188403
+ var nameStartChar = /[A-Z_a-z\xC0-\xD6\xD8-\xF6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]/;//\u10000-\uEFFFF
188404
+ var nameChar = new RegExp("[\\-\\.0-9"+nameStartChar.source.slice(1,-1)+"\\u00B7\\u0300-\\u036F\\u203F-\\u2040]");
188405
+ var tagNamePattern = new RegExp('^'+nameStartChar.source+nameChar.source+'*(?:\:'+nameStartChar.source+nameChar.source+'*)?$');
188406
+ //var tagNamePattern = /^[a-zA-Z_][\w\-\.]*(?:\:[a-zA-Z_][\w\-\.]*)?$/
188407
+
188245
188408
  conventions.assign = assign;
188246
188409
  conventions.find = find;
188247
188410
  conventions.freeze = freeze;
188248
188411
  conventions.MIME_TYPE = MIME_TYPE;
188249
188412
  conventions.NAMESPACE = NAMESPACE;
188413
+ conventions.nameStartChar = nameStartChar;
188414
+ conventions.nameChar = nameChar;
188415
+ conventions.tagNamePattern = tagNamePattern;
188250
188416
  return conventions;
188251
188417
  }
188252
188418
 
@@ -188259,6 +188425,7 @@ function requireDom () {
188259
188425
 
188260
188426
  var find = conventions.find;
188261
188427
  var NAMESPACE = conventions.NAMESPACE;
188428
+ var tagNamePattern = conventions.tagNamePattern;
188262
188429
 
188263
188430
  /**
188264
188431
  * A prerequisite for `[].filter`, to drop elements that are empty
@@ -188490,6 +188657,13 @@ function requireDom () {
188490
188657
  * used for attributes or DocumentType entities
188491
188658
  */
188492
188659
  function NamedNodeMap() {
188660
+ // nodeName -> Attr membership index; lets the parse-time de-duplication in
188661
+ // setNamedItem resolve an existing attribute in O(1) instead of scanning the
188662
+ // list, so building an element with M attributes costs O(M) rather than O(M^2).
188663
+ // The numbered entries and length remain the sole authority for attribute order.
188664
+ // Object.create(null) so an attribute named __proto__ or constructor is an
188665
+ // ordinary key.
188666
+ this._nameIndex = Object.create(null);
188493
188667
  }
188494
188668
  function _findNodeIndex(list,node){
188495
188669
  var i = list.length;
@@ -188498,12 +188672,27 @@ function requireDom () {
188498
188672
  }
188499
188673
  }
188500
188674
 
188675
+ function _nnmIndexAdd(list, attr) {
188676
+ list._nameIndex[attr.nodeName] = attr;
188677
+ }
188678
+ function _nnmIndexRemove(list, attr) {
188679
+ // Only drop the entry if it still points at this attribute; a replacement with
188680
+ // a different nodeName may already have re-keyed it.
188681
+ if (list._nameIndex[attr.nodeName] === attr) {
188682
+ delete list._nameIndex[attr.nodeName];
188683
+ }
188684
+ }
188685
+
188501
188686
  function _addNamedNode(el,list,newAttr,oldAttr){
188502
188687
  if(oldAttr){
188503
188688
  list[_findNodeIndex(list,oldAttr)] = newAttr;
188689
+ // oldAttr leaves the list; drop its index entry (its nodeName may differ
188690
+ // from newAttr's when the replacement came via setNamedItemNS).
188691
+ _nnmIndexRemove(list, oldAttr);
188504
188692
  }else {
188505
188693
  list[list.length++] = newAttr;
188506
188694
  }
188695
+ _nnmIndexAdd(list, newAttr);
188507
188696
  if(el){
188508
188697
  newAttr.ownerElement = el;
188509
188698
  var doc = el.ownerDocument;
@@ -188522,6 +188711,7 @@ function requireDom () {
188522
188711
  list[i] = list[++i];
188523
188712
  }
188524
188713
  list.length = lastIndex;
188714
+ _nnmIndexRemove(list, attr);
188525
188715
  if(el){
188526
188716
  var doc = el.ownerDocument;
188527
188717
  if(doc){
@@ -188555,7 +188745,11 @@ function requireDom () {
188555
188745
  if(el && el!=this._ownerElement){
188556
188746
  throw new DOMException(INUSE_ATTRIBUTE_ERR);
188557
188747
  }
188558
- var oldAttr = this.getNamedItem(attr.nodeName);
188748
+ // Resolve any existing attribute with the same nodeName through the O(1)
188749
+ // membership index rather than an O(M) scan — this is the parse-dedup hot
188750
+ // path (setAttributeNode per attribute during parse). Absent -> undefined,
188751
+ // matching getNamedItem's contract.
188752
+ var oldAttr = this._nameIndex[attr.nodeName];
188559
188753
  _addNamedNode(this._ownerElement,this,attr,oldAttr);
188560
188754
  return oldAttr;
188561
188755
  },
@@ -188788,9 +188982,38 @@ function requireDom () {
188788
188982
  while (child) {
188789
188983
  var next = child.nextSibling;
188790
188984
  if (next !== null && next.nodeType === TEXT_NODE && child.nodeType === TEXT_NODE) {
188791
- node.removeChild(next);
188792
- child.appendData(next.data);
188793
- // Do not advance child: re-check new nextSibling for another text run
188985
+ // Merge the whole run of adjacent text nodes at once: gather the
188986
+ // following text siblings' data, unlink them in a single pass, and
188987
+ // re-index the child list a single time. Per-sibling `removeChild`
188988
+ // (each an O(K) re-index) plus per-sibling `appendData` (each an O(K)
188989
+ // string rebuild) is O(K^2) over a long run of single-character text
188990
+ // nodes; this keeps it O(K). The first text node of the run survives
188991
+ // and carries the concatenated data, preserving node identity and
188992
+ // locator semantics.
188993
+ var tail = [];
188994
+ var sibling = next;
188995
+ while (sibling !== null && sibling.nodeType === TEXT_NODE) {
188996
+ tail.push(sibling.data);
188997
+ sibling = sibling.nextSibling;
188998
+ }
188999
+ // `sibling` is now the first non-text node after the run, or null.
189000
+ var removed = child.nextSibling;
189001
+ while (removed !== sibling) {
189002
+ var following = removed.nextSibling;
189003
+ removed.parentNode = null;
189004
+ removed.previousSibling = null;
189005
+ removed.nextSibling = null;
189006
+ removed = following;
189007
+ }
189008
+ child.nextSibling = sibling;
189009
+ if (sibling !== null) {
189010
+ sibling.previousSibling = child;
189011
+ } else {
189012
+ node.lastChild = child;
189013
+ }
189014
+ child.appendData(tail.join('')); // single O(K) string rebuild
189015
+ _onUpdateChild(node.ownerDocument, node); // single O(K) re-index
189016
+ child = sibling;
188794
189017
  } else {
188795
189018
  child = next;
188796
189019
  }
@@ -189601,8 +189824,10 @@ function requireDom () {
189601
189824
  * - it does not do any input validation on the arguments and doesn't throw "InvalidCharacterError".
189602
189825
  *
189603
189826
  * Note: When the resulting document is serialized with `requireWellFormed: true`, the
189604
- * serializer throws with code `INVALID_STATE_ERR` if `.data` contains `?>` (W3C DOM Parsing
189605
- * §3.2.1.7). Without that option the data is emitted verbatim.
189827
+ * serializer throws with code `INVALID_STATE_ERR` if `.target` is not a valid XML `NCName`
189828
+ * (a `Name` with no colon) or is an ASCII case-insensitive match for `"xml"`, or if `.data`
189829
+ * contains `?>` (W3C DOM Parsing §3.2.1.7). Without that option the target and data are
189830
+ * emitted verbatim.
189606
189831
  *
189607
189832
  * @param {string} target
189608
189833
  * @param {string} data
@@ -189627,7 +189852,27 @@ function requireDom () {
189627
189852
  node.specified = true;
189628
189853
  return node;
189629
189854
  },
189855
+ /**
189856
+ * Creates an EntityReference object, serialized as `&name;`.
189857
+ *
189858
+ * The `name` is validated against the XML `Name` production at creation time; an invalid name
189859
+ * throws a `DOMException` with code `INVALID_CHARACTER_ERR`. When the resulting node is
189860
+ * serialized with `requireWellFormed: true`, the serializer re-validates `nodeName` and throws
189861
+ * a `DOMException` with code `INVALID_STATE_ERR` if a later `nodeName` mutation made it invalid;
189862
+ * without that option the name is emitted verbatim.
189863
+ *
189864
+ * Note: xmldom does not expand entities — the parser resolves entity references inline and never
189865
+ * constructs `EntityReference` nodes, so this method is the only producer.
189866
+ *
189867
+ * @param {string} name The name of the entity to reference.
189868
+ * @returns {EntityReference}
189869
+ * @throws {DOMException} With code `INVALID_CHARACTER_ERR` when `name` is not a valid XML `Name`.
189870
+ * @see https://www.w3.org/TR/DOM-Level-3-Core/core.html#ID-392B75AE
189871
+ */
189630
189872
  createEntityReference : function(name){
189873
+ if (!tagNamePattern.test(name)) {
189874
+ throw new DOMException(INVALID_CHARACTER_ERR, 'not a valid xml name "' + name + '"');
189875
+ }
189631
189876
  var node = new EntityReference();
189632
189877
  node.ownerDocument = this;
189633
189878
  node.nodeName = name;
@@ -189839,15 +190084,16 @@ function requireDom () {
189839
190084
  /**
189840
190085
  * Represents a DocumentType node (the `<!DOCTYPE ...>` declaration).
189841
190086
  *
189842
- * `publicId`, `systemId`, and `internalSubset` are plain own-property assignments.
190087
+ * `name`, `publicId`, `systemId`, and `internalSubset` are plain own-property assignments.
189843
190088
  * xmldom does not enforce the `readonly` constraint declared by the WHATWG DOM spec —
189844
190089
  * direct property writes succeed silently. Values are serialized verbatim when
189845
190090
  * `requireWellFormed` is false (the default). When the serializer is invoked with
189846
190091
  * `requireWellFormed: true` (via the 4th-parameter options object), it validates each
189847
- * field and throws `DOMException` with code `INVALID_STATE_ERR` on invalid values.
190092
+ * field — including `name`, which is checked against the XML `Name` production — and throws
190093
+ * `DOMException` with code `INVALID_STATE_ERR` on invalid values.
189848
190094
  *
189849
190095
  * @class
189850
- * @see https://developer.mozilla.org/en-US/docs/Web/API/DocumentType MDN
190096
+ * @see https://developer.mozilla.org/docs/Web/API/DocumentType MDN
189851
190097
  */
189852
190098
  function DocumentType() {
189853
190099
  } DocumentType.prototype.nodeType = DOCUMENT_TYPE_NODE;
@@ -189861,6 +190107,20 @@ function requireDom () {
189861
190107
  } Entity.prototype.nodeType = ENTITY_NODE;
189862
190108
  _extends(Entity,Node);
189863
190109
 
190110
+ /**
190111
+ * Represents an EntityReference node, serialized as `&nodeName;`.
190112
+ *
190113
+ * `nodeName` is the referenced entity's name, stored verbatim. When serialized with
190114
+ * `requireWellFormed: true`, the serializer validates `nodeName` against the XML `Name` production
190115
+ * and throws a `DOMException` with code `INVALID_STATE_ERR` if it does not match; without that
190116
+ * option the name is emitted verbatim between `&` and `;`.
190117
+ *
190118
+ * Note: xmldom does not expand entities — the parser resolves entity references inline and never
190119
+ * constructs `EntityReference` nodes, so the only producer is `Document.createEntityReference`.
190120
+ *
190121
+ * @class
190122
+ * @see https://www.w3.org/TR/xml/#NT-Name
190123
+ */
189864
190124
  function EntityReference() {
189865
190125
  } EntityReference.prototype.nodeType = ENTITY_REFERENCE_NODE;
189866
190126
  _extends(EntityReference,Node);
@@ -189898,14 +190158,20 @@ function requireDom () {
189898
190158
  * @returns {string}
189899
190159
  * @throws {DOMException}
189900
190160
  * With code `INVALID_STATE_ERR` when `requireWellFormed` is `true` and:
190161
+ * - an Element's qualified name (including any namespace prefix) is not a valid XML QName,
190162
+ * - an attribute's qualified name (including a synthesized `xmlns:` namespace declaration) is
190163
+ * not a valid XML QName,
189901
190164
  * - a CDATASection node's data contains `"]]>"`,
189902
190165
  * - a Comment node's data contains `"-->"` (bare `"--"` does not throw on this branch),
189903
- * - a ProcessingInstruction's data contains `"?>"`,
190166
+ * - a ProcessingInstruction's target is not a valid XML `NCName` (a `Name` with no colon) or is
190167
+ * an ASCII case-insensitive match for `"xml"`, or its data contains `"?>"`,
190168
+ * - a DocumentType's `name` is not a valid XML `Name` (XML 1.0 production [5]),
189904
190169
  * - a DocumentType's `publicId` is non-empty and does not match the XML `PubidLiteral`
189905
190170
  * production,
189906
190171
  * - a DocumentType's `systemId` is non-empty and does not match the XML `SystemLiteral`
189907
- * production, or
189908
- * - a DocumentType's `internalSubset` contains `"]>"`.
190172
+ * production,
190173
+ * - a DocumentType's `internalSubset` contains `"]>"`, or
190174
+ * - an EntityReference's `nodeName` is not a valid XML `Name` (XML 1.0 production [5]).
189909
190175
  * Note: xmldom does not enforce `readonly` on DocumentType fields — direct property
189910
190176
  * writes succeed and are covered by the serializer-level checks above.
189911
190177
  * @see https://html.spec.whatwg.org/#dom-xmlserializer-serializetostring
@@ -189979,7 +190245,10 @@ function requireDom () {
189979
190245
  * @see https://www.w3.org/TR/xml11/#AVNormalize
189980
190246
  * @see https://w3c.github.io/DOM-Parsing/#serializing-an-element-s-attributes
189981
190247
  */
189982
- function addSerializedAttribute(buf, qualifiedName, value) {
190248
+ function addSerializedAttribute(buf, qualifiedName, value, requireWellFormed) {
190249
+ if (requireWellFormed && !tagNamePattern.test(qualifiedName)) {
190250
+ throw new DOMException(INVALID_STATE_ERR, 'The attribute name "' + qualifiedName + '" is not a valid XML QName');
190251
+ }
189983
190252
  buf.push(' ', qualifiedName, '="', value.replace(/[<>&"\t\n\r]/g, _xmlEncoder), '"');
189984
190253
  }
189985
190254
 
@@ -190045,6 +190314,9 @@ function requireDom () {
190045
190314
  }
190046
190315
  }
190047
190316
 
190317
+ if (requireWellFormed && !tagNamePattern.test(prefixedNodeName)) {
190318
+ throw new DOMException(INVALID_STATE_ERR, 'The element name "' + prefixedNodeName + '" is not a valid XML QName');
190319
+ }
190048
190320
  buf.push('<', prefixedNodeName);
190049
190321
 
190050
190322
  // Build a fresh namespace snapshot for this element's children.
@@ -190064,7 +190336,7 @@ function requireDom () {
190064
190336
  if (needNamespaceDefine(attr, html, childNs)) {
190065
190337
  var attrPrefix = attr.prefix || '';
190066
190338
  var uri = attr.namespaceURI;
190067
- addSerializedAttribute(buf, attrPrefix ? 'xmlns:' + attrPrefix : 'xmlns', uri);
190339
+ addSerializedAttribute(buf, attrPrefix ? 'xmlns:' + attrPrefix : 'xmlns', uri, requireWellFormed);
190068
190340
  childNs.push({ prefix: attrPrefix, namespace: uri });
190069
190341
  }
190070
190342
  // Apply nodeFilter and serialize the attribute.
@@ -190073,7 +190345,7 @@ function requireDom () {
190073
190345
  if (typeof filteredAttr === 'string') {
190074
190346
  buf.push(filteredAttr);
190075
190347
  } else {
190076
- addSerializedAttribute(buf, filteredAttr.name, filteredAttr.value);
190348
+ addSerializedAttribute(buf, filteredAttr.name, filteredAttr.value, requireWellFormed);
190077
190349
  }
190078
190350
  }
190079
190351
  }
@@ -190082,7 +190354,7 @@ function requireDom () {
190082
190354
  if (nodeName === prefixedNodeName && needNamespaceDefine(n, html, childNs)) {
190083
190355
  var nodePrefix = n.prefix || '';
190084
190356
  var uri = n.namespaceURI;
190085
- addSerializedAttribute(buf, nodePrefix ? 'xmlns:' + nodePrefix : 'xmlns', uri);
190357
+ addSerializedAttribute(buf, nodePrefix ? 'xmlns:' + nodePrefix : 'xmlns', uri, requireWellFormed);
190086
190358
  childNs.push({ prefix: nodePrefix, namespace: uri });
190087
190359
  }
190088
190360
 
@@ -190115,7 +190387,7 @@ function requireDom () {
190115
190387
  return { ns: ns.slice(), isHTML: html, tag: null };
190116
190388
 
190117
190389
  case ATTRIBUTE_NODE:
190118
- addSerializedAttribute(buf, n.name, n.value);
190390
+ addSerializedAttribute(buf, n.name, n.value, requireWellFormed);
190119
190391
  return null;
190120
190392
 
190121
190393
  case TEXT_NODE:
@@ -190154,6 +190426,9 @@ function requireDom () {
190154
190426
 
190155
190427
  case DOCUMENT_TYPE_NODE:
190156
190428
  if (requireWellFormed) {
190429
+ if (!tagNamePattern.test(n.name)) {
190430
+ throw new DOMException(INVALID_STATE_ERR, 'The doctype name "' + n.name + '" is not a valid XML Name');
190431
+ }
190157
190432
  if (n.publicId && !/^("[\x20\r\na-zA-Z0-9\-()+,.\/:=?;!*#@$_%']*"|'[\x20\r\na-zA-Z0-9\-()+,.\/:=?;!*#@$_%'"]*')$/.test(n.publicId)) {
190158
190433
  throw new DOMException(INVALID_STATE_ERR, 'DocumentType publicId is not a valid PubidLiteral');
190159
190434
  }
@@ -190185,13 +190460,27 @@ function requireDom () {
190185
190460
  return null;
190186
190461
 
190187
190462
  case PROCESSING_INSTRUCTION_NODE:
190188
- if (requireWellFormed && n.data.indexOf('?>') !== -1) {
190189
- throw new DOMException(INVALID_STATE_ERR, 'The ProcessingInstruction data contains "?>"');
190463
+ if (requireWellFormed) {
190464
+ if (!tagNamePattern.test(n.target) || n.target.indexOf(':') !== -1 || n.target.toLowerCase() === 'xml') {
190465
+ throw new DOMException(
190466
+ INVALID_STATE_ERR,
190467
+ 'The processing instruction target "' + n.target + '" is not a valid XML NCName or is reserved'
190468
+ );
190469
+ }
190470
+ if (n.data.indexOf('?>') !== -1) {
190471
+ throw new DOMException(INVALID_STATE_ERR, 'The ProcessingInstruction data contains "?>"');
190472
+ }
190190
190473
  }
190191
190474
  buf.push('<?', n.target, ' ', n.data, '?>');
190192
190475
  return null;
190193
190476
 
190194
190477
  case ENTITY_REFERENCE_NODE:
190478
+ if (requireWellFormed && !tagNamePattern.test(n.nodeName)) {
190479
+ throw new DOMException(
190480
+ INVALID_STATE_ERR,
190481
+ 'The entity reference name "' + n.nodeName + '" is not a valid XML Name'
190482
+ );
190483
+ }
190195
190484
  buf.push('&', n.nodeName, ';');
190196
190485
  return null;
190197
190486
 
@@ -192572,14 +192861,8 @@ function requireSax () {
192572
192861
  if (hasRequiredSax) return sax;
192573
192862
  hasRequiredSax = 1;
192574
192863
  var NAMESPACE = requireConventions().NAMESPACE;
192864
+ var tagNamePattern = requireConventions().tagNamePattern;
192575
192865
 
192576
- //[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]
192577
- //[4a] NameChar ::= NameStartChar | "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] | [#x203F-#x2040]
192578
- //[5] Name ::= NameStartChar (NameChar)*
192579
- var nameStartChar = /[A-Z_a-z\xC0-\xD6\xD8-\xF6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]/;//\u10000-\uEFFFF
192580
- var nameChar = new RegExp("[\\-\\.0-9"+nameStartChar.source.slice(1,-1)+"\\u00B7\\u0300-\\u036F\\u203F-\\u2040]");
192581
- var tagNamePattern = new RegExp('^'+nameStartChar.source+nameChar.source+'*(?:\:'+nameStartChar.source+nameChar.source+'*)?$');
192582
- //var tagNamePattern = /^[a-zA-Z_][\w\-\.]*(?:\:[a-zA-Z_][\w\-\.]*)?$/
192583
192866
  //var handlers = 'resolveEntity,getExternalSubset,characters,endDocument,endElement,endPrefixMapping,ignorableWhitespace,processingInstruction,setDocumentLocator,skippedEntity,startDocument,startElement,startPrefixMapping,notationDecl,unparsedEntityDecl,error,fatalError,warning,attributeDecl,elementDecl,externalEntityDecl,internalEntityDecl,comment,endCDATA,endDTD,endEntity,startCDATA,startDTD,startEntity'.split(',')
192584
192867
 
192585
192868
  //S_TAG, S_ATTR, S_EQ, S_ATTR_NOQUOT_VALUE
@@ -192690,7 +192973,13 @@ function requireSax () {
192690
192973
  switch(source.charAt(tagStart+1)){
192691
192974
  case '/':
192692
192975
  var end = source.indexOf('>',tagStart+3);
192693
- var tagName = source.substring(tagStart + 2, end).replace(/[ \t\n\r]+$/g, '');
192976
+ // Anchored trailing-whitespace trim. The former `/[ \t\n\r]+$/g` backtracked
192977
+ // quadratically on a name shaped `whitespace-run + non-whitespace char`
192978
+ // (an end tag `</ … x>`): from every start position it extended `[ws]+`
192979
+ // to the end and then failed the `$` anchor. This anchored form matches the
192980
+ // whole string once and captures everything up to the last non-whitespace
192981
+ // character, so it trims in linear time with byte-identical output.
192982
+ var tagName = source.substring(tagStart + 2, end).replace(/^([\s\S]*?[^ \t\n\r])?[ \t\n\r]*$/, '$1');
192694
192983
  var config = parseStack.pop();
192695
192984
  if(end<0){
192696
192985
 
@@ -192701,6 +192990,14 @@ function requireSax () {
192701
192990
  tagName = tagName.replace(/[\s<].*/,'');
192702
192991
  errorHandler.error("end tag name: "+tagName+' maybe not complete');
192703
192992
  end = tagStart+1+tagName.length;
192993
+ }else if(/[ \t\n\r]/.test(tagName) && tagNamePattern.test(tagName.split(/[ \t\n\r]/)[0])){
192994
+ // The XML `ETag` production is `'</' Name S? '>'`: only optional whitespace may follow
192995
+ // the `Name`. A valid `Name` followed by whitespace and non-whitespace residue (e.g.
192996
+ // `</a\nbogus>` or `</a bogus>`) is not well-formed, but historically it was silently
192997
+ // accepted (the malformed end tag ignored, the residue dropped, the element left on the
192998
+ // stack). Report it as a recoverable `error` (which a custom errorHandler may escalate to
192999
+ // fatal) while keeping the existing recovery so the parsed DOM stays byte-identical.
193000
+ errorHandler.error('end tag name is followed by whitespace and trailing content: "'+tagName+'"');
192704
193001
  }
192705
193002
  var localNSMap = config.localNSMap;
192706
193003
  var endMatch = config.tagName == tagName;
@@ -192824,6 +193121,15 @@ function requireSax () {
192824
193121
  var s = S_TAG;//status
192825
193122
  while(true){
192826
193123
  var c = source.charAt(p);
193124
+ if (s === S_TAG && c === '<') {
193125
+ // A `<` can never occur inside a tag name. Without this guard the scan runs
193126
+ // on to the next `>` (or EOF) before the tag name is rejected, so a document
193127
+ // with many `<` inside a malformed tag makes each one-character recovery step
193128
+ // re-scan to the distant `>` — O(n^2). Stopping at the `<` keeps each recovery
193129
+ // step bounded. The candidate scanned so far is reported raw, consistent with
193130
+ // the sibling invalid-tag-name throw below.
193131
+ throw new Error('unexpected < in tag name: ' + source.slice(start, p));
193132
+ }
192827
193133
  switch(c){
192828
193134
  case '=':
192829
193135
  if(s === S_ATTR){//attrName
@@ -193016,9 +193322,13 @@ function requireSax () {
193016
193322
  if(nsPrefix !== false){//hack!!
193017
193323
  if(localNSMap == null){
193018
193324
  localNSMap = {};
193019
- //console.log(currentNSMap,0)
193020
- _copy(currentNSMap,currentNSMap={});
193021
- //console.log(currentNSMap,1)
193325
+ // Derive the child scope's namespace map by prototype-chain inheritance
193326
+ // instead of a flat copy: lookups inherit ancestor prefixes transparently,
193327
+ // so a document nesting N scopes retains O(N) map entries rather than
193328
+ // sum(1..N) = O(N^2). localNSMap stays a flat own-only record of the
193329
+ // prefixes declared at THIS element, so own-property enumeration
193330
+ // (endPrefixMapping below) still reports only local declarations.
193331
+ currentNSMap = Object.create(currentNSMap);
193022
193332
  }
193023
193333
  currentNSMap[nsPrefix] = localNSMap[nsPrefix] = value;
193024
193334
  a.uri = NAMESPACE.XMLNS;