@wavemaker/angular-codegen 11.14.1-26.647686 → 11.14.1-28.647720

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.
@@ -131162,11 +131162,22 @@ function requireConventions$1 () {
131162
131162
  XMLNS: 'http://www.w3.org/2000/xmlns/',
131163
131163
  });
131164
131164
 
131165
+ //[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]
131166
+ //[4a] NameChar ::= NameStartChar | "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] | [#x203F-#x2040]
131167
+ //[5] Name ::= NameStartChar (NameChar)*
131168
+ 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
131169
+ var nameChar = new RegExp("[\\-\\.0-9"+nameStartChar.source.slice(1,-1)+"\\u00B7\\u0300-\\u036F\\u203F-\\u2040]");
131170
+ var tagNamePattern = new RegExp('^'+nameStartChar.source+nameChar.source+'*(?:\:'+nameStartChar.source+nameChar.source+'*)?$');
131171
+ //var tagNamePattern = /^[a-zA-Z_][\w\-\.]*(?:\:[a-zA-Z_][\w\-\.]*)?$/
131172
+
131165
131173
  conventions$1.assign = assign;
131166
131174
  conventions$1.find = find;
131167
131175
  conventions$1.freeze = freeze;
131168
131176
  conventions$1.MIME_TYPE = MIME_TYPE;
131169
131177
  conventions$1.NAMESPACE = NAMESPACE;
131178
+ conventions$1.nameStartChar = nameStartChar;
131179
+ conventions$1.nameChar = nameChar;
131180
+ conventions$1.tagNamePattern = tagNamePattern;
131170
131181
  return conventions$1;
131171
131182
  }
131172
131183
 
@@ -131179,6 +131190,7 @@ function requireDom$1 () {
131179
131190
 
131180
131191
  var find = conventions.find;
131181
131192
  var NAMESPACE = conventions.NAMESPACE;
131193
+ var tagNamePattern = conventions.tagNamePattern;
131182
131194
 
131183
131195
  /**
131184
131196
  * A prerequisite for `[].filter`, to drop elements that are empty
@@ -131410,6 +131422,13 @@ function requireDom$1 () {
131410
131422
  * used for attributes or DocumentType entities
131411
131423
  */
131412
131424
  function NamedNodeMap() {
131425
+ // nodeName -> Attr membership index; lets the parse-time de-duplication in
131426
+ // setNamedItem resolve an existing attribute in O(1) instead of scanning the
131427
+ // list, so building an element with M attributes costs O(M) rather than O(M^2).
131428
+ // The numbered entries and length remain the sole authority for attribute order.
131429
+ // Object.create(null) so an attribute named __proto__ or constructor is an
131430
+ // ordinary key.
131431
+ this._nameIndex = Object.create(null);
131413
131432
  }
131414
131433
  function _findNodeIndex(list,node){
131415
131434
  var i = list.length;
@@ -131418,12 +131437,27 @@ function requireDom$1 () {
131418
131437
  }
131419
131438
  }
131420
131439
 
131440
+ function _nnmIndexAdd(list, attr) {
131441
+ list._nameIndex[attr.nodeName] = attr;
131442
+ }
131443
+ function _nnmIndexRemove(list, attr) {
131444
+ // Only drop the entry if it still points at this attribute; a replacement with
131445
+ // a different nodeName may already have re-keyed it.
131446
+ if (list._nameIndex[attr.nodeName] === attr) {
131447
+ delete list._nameIndex[attr.nodeName];
131448
+ }
131449
+ }
131450
+
131421
131451
  function _addNamedNode(el,list,newAttr,oldAttr){
131422
131452
  if(oldAttr){
131423
131453
  list[_findNodeIndex(list,oldAttr)] = newAttr;
131454
+ // oldAttr leaves the list; drop its index entry (its nodeName may differ
131455
+ // from newAttr's when the replacement came via setNamedItemNS).
131456
+ _nnmIndexRemove(list, oldAttr);
131424
131457
  }else {
131425
131458
  list[list.length++] = newAttr;
131426
131459
  }
131460
+ _nnmIndexAdd(list, newAttr);
131427
131461
  if(el){
131428
131462
  newAttr.ownerElement = el;
131429
131463
  var doc = el.ownerDocument;
@@ -131442,6 +131476,7 @@ function requireDom$1 () {
131442
131476
  list[i] = list[++i];
131443
131477
  }
131444
131478
  list.length = lastIndex;
131479
+ _nnmIndexRemove(list, attr);
131445
131480
  if(el){
131446
131481
  var doc = el.ownerDocument;
131447
131482
  if(doc){
@@ -131475,7 +131510,11 @@ function requireDom$1 () {
131475
131510
  if(el && el!=this._ownerElement){
131476
131511
  throw new DOMException(INUSE_ATTRIBUTE_ERR);
131477
131512
  }
131478
- var oldAttr = this.getNamedItem(attr.nodeName);
131513
+ // Resolve any existing attribute with the same nodeName through the O(1)
131514
+ // membership index rather than an O(M) scan — this is the parse-dedup hot
131515
+ // path (setAttributeNode per attribute during parse). Absent -> undefined,
131516
+ // matching getNamedItem's contract.
131517
+ var oldAttr = this._nameIndex[attr.nodeName];
131479
131518
  _addNamedNode(this._ownerElement,this,attr,oldAttr);
131480
131519
  return oldAttr;
131481
131520
  },
@@ -131708,9 +131747,38 @@ function requireDom$1 () {
131708
131747
  while (child) {
131709
131748
  var next = child.nextSibling;
131710
131749
  if (next !== null && next.nodeType === TEXT_NODE && child.nodeType === TEXT_NODE) {
131711
- node.removeChild(next);
131712
- child.appendData(next.data);
131713
- // Do not advance child: re-check new nextSibling for another text run
131750
+ // Merge the whole run of adjacent text nodes at once: gather the
131751
+ // following text siblings' data, unlink them in a single pass, and
131752
+ // re-index the child list a single time. Per-sibling `removeChild`
131753
+ // (each an O(K) re-index) plus per-sibling `appendData` (each an O(K)
131754
+ // string rebuild) is O(K^2) over a long run of single-character text
131755
+ // nodes; this keeps it O(K). The first text node of the run survives
131756
+ // and carries the concatenated data, preserving node identity and
131757
+ // locator semantics.
131758
+ var tail = [];
131759
+ var sibling = next;
131760
+ while (sibling !== null && sibling.nodeType === TEXT_NODE) {
131761
+ tail.push(sibling.data);
131762
+ sibling = sibling.nextSibling;
131763
+ }
131764
+ // `sibling` is now the first non-text node after the run, or null.
131765
+ var removed = child.nextSibling;
131766
+ while (removed !== sibling) {
131767
+ var following = removed.nextSibling;
131768
+ removed.parentNode = null;
131769
+ removed.previousSibling = null;
131770
+ removed.nextSibling = null;
131771
+ removed = following;
131772
+ }
131773
+ child.nextSibling = sibling;
131774
+ if (sibling !== null) {
131775
+ sibling.previousSibling = child;
131776
+ } else {
131777
+ node.lastChild = child;
131778
+ }
131779
+ child.appendData(tail.join('')); // single O(K) string rebuild
131780
+ _onUpdateChild(node.ownerDocument, node); // single O(K) re-index
131781
+ child = sibling;
131714
131782
  } else {
131715
131783
  child = next;
131716
131784
  }
@@ -132521,8 +132589,10 @@ function requireDom$1 () {
132521
132589
  * - it does not do any input validation on the arguments and doesn't throw "InvalidCharacterError".
132522
132590
  *
132523
132591
  * Note: When the resulting document is serialized with `requireWellFormed: true`, the
132524
- * serializer throws with code `INVALID_STATE_ERR` if `.data` contains `?>` (W3C DOM Parsing
132525
- * §3.2.1.7). Without that option the data is emitted verbatim.
132592
+ * serializer throws with code `INVALID_STATE_ERR` if `.target` is not a valid XML `NCName`
132593
+ * (a `Name` with no colon) or is an ASCII case-insensitive match for `"xml"`, or if `.data`
132594
+ * contains `?>` (W3C DOM Parsing §3.2.1.7). Without that option the target and data are
132595
+ * emitted verbatim.
132526
132596
  *
132527
132597
  * @param {string} target
132528
132598
  * @param {string} data
@@ -132547,7 +132617,27 @@ function requireDom$1 () {
132547
132617
  node.specified = true;
132548
132618
  return node;
132549
132619
  },
132620
+ /**
132621
+ * Creates an EntityReference object, serialized as `&name;`.
132622
+ *
132623
+ * The `name` is validated against the XML `Name` production at creation time; an invalid name
132624
+ * throws a `DOMException` with code `INVALID_CHARACTER_ERR`. When the resulting node is
132625
+ * serialized with `requireWellFormed: true`, the serializer re-validates `nodeName` and throws
132626
+ * a `DOMException` with code `INVALID_STATE_ERR` if a later `nodeName` mutation made it invalid;
132627
+ * without that option the name is emitted verbatim.
132628
+ *
132629
+ * Note: xmldom does not expand entities — the parser resolves entity references inline and never
132630
+ * constructs `EntityReference` nodes, so this method is the only producer.
132631
+ *
132632
+ * @param {string} name The name of the entity to reference.
132633
+ * @returns {EntityReference}
132634
+ * @throws {DOMException} With code `INVALID_CHARACTER_ERR` when `name` is not a valid XML `Name`.
132635
+ * @see https://www.w3.org/TR/DOM-Level-3-Core/core.html#ID-392B75AE
132636
+ */
132550
132637
  createEntityReference : function(name){
132638
+ if (!tagNamePattern.test(name)) {
132639
+ throw new DOMException(INVALID_CHARACTER_ERR, 'not a valid xml name "' + name + '"');
132640
+ }
132551
132641
  var node = new EntityReference();
132552
132642
  node.ownerDocument = this;
132553
132643
  node.nodeName = name;
@@ -132759,15 +132849,16 @@ function requireDom$1 () {
132759
132849
  /**
132760
132850
  * Represents a DocumentType node (the `<!DOCTYPE ...>` declaration).
132761
132851
  *
132762
- * `publicId`, `systemId`, and `internalSubset` are plain own-property assignments.
132852
+ * `name`, `publicId`, `systemId`, and `internalSubset` are plain own-property assignments.
132763
132853
  * xmldom does not enforce the `readonly` constraint declared by the WHATWG DOM spec —
132764
132854
  * direct property writes succeed silently. Values are serialized verbatim when
132765
132855
  * `requireWellFormed` is false (the default). When the serializer is invoked with
132766
132856
  * `requireWellFormed: true` (via the 4th-parameter options object), it validates each
132767
- * field and throws `DOMException` with code `INVALID_STATE_ERR` on invalid values.
132857
+ * field — including `name`, which is checked against the XML `Name` production — and throws
132858
+ * `DOMException` with code `INVALID_STATE_ERR` on invalid values.
132768
132859
  *
132769
132860
  * @class
132770
- * @see https://developer.mozilla.org/en-US/docs/Web/API/DocumentType MDN
132861
+ * @see https://developer.mozilla.org/docs/Web/API/DocumentType MDN
132771
132862
  */
132772
132863
  function DocumentType() {
132773
132864
  } DocumentType.prototype.nodeType = DOCUMENT_TYPE_NODE;
@@ -132781,6 +132872,20 @@ function requireDom$1 () {
132781
132872
  } Entity.prototype.nodeType = ENTITY_NODE;
132782
132873
  _extends(Entity,Node);
132783
132874
 
132875
+ /**
132876
+ * Represents an EntityReference node, serialized as `&nodeName;`.
132877
+ *
132878
+ * `nodeName` is the referenced entity's name, stored verbatim. When serialized with
132879
+ * `requireWellFormed: true`, the serializer validates `nodeName` against the XML `Name` production
132880
+ * and throws a `DOMException` with code `INVALID_STATE_ERR` if it does not match; without that
132881
+ * option the name is emitted verbatim between `&` and `;`.
132882
+ *
132883
+ * Note: xmldom does not expand entities — the parser resolves entity references inline and never
132884
+ * constructs `EntityReference` nodes, so the only producer is `Document.createEntityReference`.
132885
+ *
132886
+ * @class
132887
+ * @see https://www.w3.org/TR/xml/#NT-Name
132888
+ */
132784
132889
  function EntityReference() {
132785
132890
  } EntityReference.prototype.nodeType = ENTITY_REFERENCE_NODE;
132786
132891
  _extends(EntityReference,Node);
@@ -132818,14 +132923,20 @@ function requireDom$1 () {
132818
132923
  * @returns {string}
132819
132924
  * @throws {DOMException}
132820
132925
  * With code `INVALID_STATE_ERR` when `requireWellFormed` is `true` and:
132926
+ * - an Element's qualified name (including any namespace prefix) is not a valid XML QName,
132927
+ * - an attribute's qualified name (including a synthesized `xmlns:` namespace declaration) is
132928
+ * not a valid XML QName,
132821
132929
  * - a CDATASection node's data contains `"]]>"`,
132822
132930
  * - a Comment node's data contains `"-->"` (bare `"--"` does not throw on this branch),
132823
- * - a ProcessingInstruction's data contains `"?>"`,
132931
+ * - a ProcessingInstruction's target is not a valid XML `NCName` (a `Name` with no colon) or is
132932
+ * an ASCII case-insensitive match for `"xml"`, or its data contains `"?>"`,
132933
+ * - a DocumentType's `name` is not a valid XML `Name` (XML 1.0 production [5]),
132824
132934
  * - a DocumentType's `publicId` is non-empty and does not match the XML `PubidLiteral`
132825
132935
  * production,
132826
132936
  * - a DocumentType's `systemId` is non-empty and does not match the XML `SystemLiteral`
132827
- * production, or
132828
- * - a DocumentType's `internalSubset` contains `"]>"`.
132937
+ * production,
132938
+ * - a DocumentType's `internalSubset` contains `"]>"`, or
132939
+ * - an EntityReference's `nodeName` is not a valid XML `Name` (XML 1.0 production [5]).
132829
132940
  * Note: xmldom does not enforce `readonly` on DocumentType fields — direct property
132830
132941
  * writes succeed and are covered by the serializer-level checks above.
132831
132942
  * @see https://html.spec.whatwg.org/#dom-xmlserializer-serializetostring
@@ -132899,7 +133010,10 @@ function requireDom$1 () {
132899
133010
  * @see https://www.w3.org/TR/xml11/#AVNormalize
132900
133011
  * @see https://w3c.github.io/DOM-Parsing/#serializing-an-element-s-attributes
132901
133012
  */
132902
- function addSerializedAttribute(buf, qualifiedName, value) {
133013
+ function addSerializedAttribute(buf, qualifiedName, value, requireWellFormed) {
133014
+ if (requireWellFormed && !tagNamePattern.test(qualifiedName)) {
133015
+ throw new DOMException(INVALID_STATE_ERR, 'The attribute name "' + qualifiedName + '" is not a valid XML QName');
133016
+ }
132903
133017
  buf.push(' ', qualifiedName, '="', value.replace(/[<>&"\t\n\r]/g, _xmlEncoder), '"');
132904
133018
  }
132905
133019
 
@@ -132965,6 +133079,9 @@ function requireDom$1 () {
132965
133079
  }
132966
133080
  }
132967
133081
 
133082
+ if (requireWellFormed && !tagNamePattern.test(prefixedNodeName)) {
133083
+ throw new DOMException(INVALID_STATE_ERR, 'The element name "' + prefixedNodeName + '" is not a valid XML QName');
133084
+ }
132968
133085
  buf.push('<', prefixedNodeName);
132969
133086
 
132970
133087
  // Build a fresh namespace snapshot for this element's children.
@@ -132984,7 +133101,7 @@ function requireDom$1 () {
132984
133101
  if (needNamespaceDefine(attr, html, childNs)) {
132985
133102
  var attrPrefix = attr.prefix || '';
132986
133103
  var uri = attr.namespaceURI;
132987
- addSerializedAttribute(buf, attrPrefix ? 'xmlns:' + attrPrefix : 'xmlns', uri);
133104
+ addSerializedAttribute(buf, attrPrefix ? 'xmlns:' + attrPrefix : 'xmlns', uri, requireWellFormed);
132988
133105
  childNs.push({ prefix: attrPrefix, namespace: uri });
132989
133106
  }
132990
133107
  // Apply nodeFilter and serialize the attribute.
@@ -132993,7 +133110,7 @@ function requireDom$1 () {
132993
133110
  if (typeof filteredAttr === 'string') {
132994
133111
  buf.push(filteredAttr);
132995
133112
  } else {
132996
- addSerializedAttribute(buf, filteredAttr.name, filteredAttr.value);
133113
+ addSerializedAttribute(buf, filteredAttr.name, filteredAttr.value, requireWellFormed);
132997
133114
  }
132998
133115
  }
132999
133116
  }
@@ -133002,7 +133119,7 @@ function requireDom$1 () {
133002
133119
  if (nodeName === prefixedNodeName && needNamespaceDefine(n, html, childNs)) {
133003
133120
  var nodePrefix = n.prefix || '';
133004
133121
  var uri = n.namespaceURI;
133005
- addSerializedAttribute(buf, nodePrefix ? 'xmlns:' + nodePrefix : 'xmlns', uri);
133122
+ addSerializedAttribute(buf, nodePrefix ? 'xmlns:' + nodePrefix : 'xmlns', uri, requireWellFormed);
133006
133123
  childNs.push({ prefix: nodePrefix, namespace: uri });
133007
133124
  }
133008
133125
 
@@ -133035,7 +133152,7 @@ function requireDom$1 () {
133035
133152
  return { ns: ns.slice(), isHTML: html, tag: null };
133036
133153
 
133037
133154
  case ATTRIBUTE_NODE:
133038
- addSerializedAttribute(buf, n.name, n.value);
133155
+ addSerializedAttribute(buf, n.name, n.value, requireWellFormed);
133039
133156
  return null;
133040
133157
 
133041
133158
  case TEXT_NODE:
@@ -133074,6 +133191,9 @@ function requireDom$1 () {
133074
133191
 
133075
133192
  case DOCUMENT_TYPE_NODE:
133076
133193
  if (requireWellFormed) {
133194
+ if (!tagNamePattern.test(n.name)) {
133195
+ throw new DOMException(INVALID_STATE_ERR, 'The doctype name "' + n.name + '" is not a valid XML Name');
133196
+ }
133077
133197
  if (n.publicId && !/^("[\x20\r\na-zA-Z0-9\-()+,.\/:=?;!*#@$_%']*"|'[\x20\r\na-zA-Z0-9\-()+,.\/:=?;!*#@$_%'"]*')$/.test(n.publicId)) {
133078
133198
  throw new DOMException(INVALID_STATE_ERR, 'DocumentType publicId is not a valid PubidLiteral');
133079
133199
  }
@@ -133105,13 +133225,27 @@ function requireDom$1 () {
133105
133225
  return null;
133106
133226
 
133107
133227
  case PROCESSING_INSTRUCTION_NODE:
133108
- if (requireWellFormed && n.data.indexOf('?>') !== -1) {
133109
- throw new DOMException(INVALID_STATE_ERR, 'The ProcessingInstruction data contains "?>"');
133228
+ if (requireWellFormed) {
133229
+ if (!tagNamePattern.test(n.target) || n.target.indexOf(':') !== -1 || n.target.toLowerCase() === 'xml') {
133230
+ throw new DOMException(
133231
+ INVALID_STATE_ERR,
133232
+ 'The processing instruction target "' + n.target + '" is not a valid XML NCName or is reserved'
133233
+ );
133234
+ }
133235
+ if (n.data.indexOf('?>') !== -1) {
133236
+ throw new DOMException(INVALID_STATE_ERR, 'The ProcessingInstruction data contains "?>"');
133237
+ }
133110
133238
  }
133111
133239
  buf.push('<?', n.target, ' ', n.data, '?>');
133112
133240
  return null;
133113
133241
 
133114
133242
  case ENTITY_REFERENCE_NODE:
133243
+ if (requireWellFormed && !tagNamePattern.test(n.nodeName)) {
133244
+ throw new DOMException(
133245
+ INVALID_STATE_ERR,
133246
+ 'The entity reference name "' + n.nodeName + '" is not a valid XML Name'
133247
+ );
133248
+ }
133115
133249
  buf.push('&', n.nodeName, ';');
133116
133250
  return null;
133117
133251
 
@@ -135492,14 +135626,8 @@ function requireSax$1 () {
135492
135626
  if (hasRequiredSax$1) return sax$1;
135493
135627
  hasRequiredSax$1 = 1;
135494
135628
  var NAMESPACE = requireConventions$1().NAMESPACE;
135629
+ var tagNamePattern = requireConventions$1().tagNamePattern;
135495
135630
 
135496
- //[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]
135497
- //[4a] NameChar ::= NameStartChar | "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] | [#x203F-#x2040]
135498
- //[5] Name ::= NameStartChar (NameChar)*
135499
- 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
135500
- var nameChar = new RegExp("[\\-\\.0-9"+nameStartChar.source.slice(1,-1)+"\\u00B7\\u0300-\\u036F\\u203F-\\u2040]");
135501
- var tagNamePattern = new RegExp('^'+nameStartChar.source+nameChar.source+'*(?:\:'+nameStartChar.source+nameChar.source+'*)?$');
135502
- //var tagNamePattern = /^[a-zA-Z_][\w\-\.]*(?:\:[a-zA-Z_][\w\-\.]*)?$/
135503
135631
  //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(',')
135504
135632
 
135505
135633
  //S_TAG, S_ATTR, S_EQ, S_ATTR_NOQUOT_VALUE
@@ -135610,7 +135738,13 @@ function requireSax$1 () {
135610
135738
  switch(source.charAt(tagStart+1)){
135611
135739
  case '/':
135612
135740
  var end = source.indexOf('>',tagStart+3);
135613
- var tagName = source.substring(tagStart + 2, end).replace(/[ \t\n\r]+$/g, '');
135741
+ // Anchored trailing-whitespace trim. The former `/[ \t\n\r]+$/g` backtracked
135742
+ // quadratically on a name shaped `whitespace-run + non-whitespace char`
135743
+ // (an end tag `</ … x>`): from every start position it extended `[ws]+`
135744
+ // to the end and then failed the `$` anchor. This anchored form matches the
135745
+ // whole string once and captures everything up to the last non-whitespace
135746
+ // character, so it trims in linear time with byte-identical output.
135747
+ var tagName = source.substring(tagStart + 2, end).replace(/^([\s\S]*?[^ \t\n\r])?[ \t\n\r]*$/, '$1');
135614
135748
  var config = parseStack.pop();
135615
135749
  if(end<0){
135616
135750
 
@@ -135621,6 +135755,14 @@ function requireSax$1 () {
135621
135755
  tagName = tagName.replace(/[\s<].*/,'');
135622
135756
  errorHandler.error("end tag name: "+tagName+' maybe not complete');
135623
135757
  end = tagStart+1+tagName.length;
135758
+ }else if(/[ \t\n\r]/.test(tagName) && tagNamePattern.test(tagName.split(/[ \t\n\r]/)[0])){
135759
+ // The XML `ETag` production is `'</' Name S? '>'`: only optional whitespace may follow
135760
+ // the `Name`. A valid `Name` followed by whitespace and non-whitespace residue (e.g.
135761
+ // `</a\nbogus>` or `</a bogus>`) is not well-formed, but historically it was silently
135762
+ // accepted (the malformed end tag ignored, the residue dropped, the element left on the
135763
+ // stack). Report it as a recoverable `error` (which a custom errorHandler may escalate to
135764
+ // fatal) while keeping the existing recovery so the parsed DOM stays byte-identical.
135765
+ errorHandler.error('end tag name is followed by whitespace and trailing content: "'+tagName+'"');
135624
135766
  }
135625
135767
  var localNSMap = config.localNSMap;
135626
135768
  var endMatch = config.tagName == tagName;
@@ -135744,6 +135886,15 @@ function requireSax$1 () {
135744
135886
  var s = S_TAG;//status
135745
135887
  while(true){
135746
135888
  var c = source.charAt(p);
135889
+ if (s === S_TAG && c === '<') {
135890
+ // A `<` can never occur inside a tag name. Without this guard the scan runs
135891
+ // on to the next `>` (or EOF) before the tag name is rejected, so a document
135892
+ // with many `<` inside a malformed tag makes each one-character recovery step
135893
+ // re-scan to the distant `>` — O(n^2). Stopping at the `<` keeps each recovery
135894
+ // step bounded. The candidate scanned so far is reported raw, consistent with
135895
+ // the sibling invalid-tag-name throw below.
135896
+ throw new Error('unexpected < in tag name: ' + source.slice(start, p));
135897
+ }
135747
135898
  switch(c){
135748
135899
  case '=':
135749
135900
  if(s === S_ATTR){//attrName
@@ -135936,9 +136087,13 @@ function requireSax$1 () {
135936
136087
  if(nsPrefix !== false){//hack!!
135937
136088
  if(localNSMap == null){
135938
136089
  localNSMap = {};
135939
- //console.log(currentNSMap,0)
135940
- _copy(currentNSMap,currentNSMap={});
135941
- //console.log(currentNSMap,1)
136090
+ // Derive the child scope's namespace map by prototype-chain inheritance
136091
+ // instead of a flat copy: lookups inherit ancestor prefixes transparently,
136092
+ // so a document nesting N scopes retains O(N) map entries rather than
136093
+ // sum(1..N) = O(N^2). localNSMap stays a flat own-only record of the
136094
+ // prefixes declared at THIS element, so own-property enumeration
136095
+ // (endPrefixMapping below) still reports only local declarations.
136096
+ currentNSMap = Object.create(currentNSMap);
135942
136097
  }
135943
136098
  currentNSMap[nsPrefix] = localNSMap[nsPrefix] = value;
135944
136099
  a.uri = NAMESPACE.XMLNS;
@@ -188102,11 +188257,22 @@ function requireConventions () {
188102
188257
  XMLNS: 'http://www.w3.org/2000/xmlns/',
188103
188258
  });
188104
188259
 
188260
+ //[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]
188261
+ //[4a] NameChar ::= NameStartChar | "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] | [#x203F-#x2040]
188262
+ //[5] Name ::= NameStartChar (NameChar)*
188263
+ 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
188264
+ var nameChar = new RegExp("[\\-\\.0-9"+nameStartChar.source.slice(1,-1)+"\\u00B7\\u0300-\\u036F\\u203F-\\u2040]");
188265
+ var tagNamePattern = new RegExp('^'+nameStartChar.source+nameChar.source+'*(?:\:'+nameStartChar.source+nameChar.source+'*)?$');
188266
+ //var tagNamePattern = /^[a-zA-Z_][\w\-\.]*(?:\:[a-zA-Z_][\w\-\.]*)?$/
188267
+
188105
188268
  conventions.assign = assign;
188106
188269
  conventions.find = find;
188107
188270
  conventions.freeze = freeze;
188108
188271
  conventions.MIME_TYPE = MIME_TYPE;
188109
188272
  conventions.NAMESPACE = NAMESPACE;
188273
+ conventions.nameStartChar = nameStartChar;
188274
+ conventions.nameChar = nameChar;
188275
+ conventions.tagNamePattern = tagNamePattern;
188110
188276
  return conventions;
188111
188277
  }
188112
188278
 
@@ -188119,6 +188285,7 @@ function requireDom () {
188119
188285
 
188120
188286
  var find = conventions.find;
188121
188287
  var NAMESPACE = conventions.NAMESPACE;
188288
+ var tagNamePattern = conventions.tagNamePattern;
188122
188289
 
188123
188290
  /**
188124
188291
  * A prerequisite for `[].filter`, to drop elements that are empty
@@ -188350,6 +188517,13 @@ function requireDom () {
188350
188517
  * used for attributes or DocumentType entities
188351
188518
  */
188352
188519
  function NamedNodeMap() {
188520
+ // nodeName -> Attr membership index; lets the parse-time de-duplication in
188521
+ // setNamedItem resolve an existing attribute in O(1) instead of scanning the
188522
+ // list, so building an element with M attributes costs O(M) rather than O(M^2).
188523
+ // The numbered entries and length remain the sole authority for attribute order.
188524
+ // Object.create(null) so an attribute named __proto__ or constructor is an
188525
+ // ordinary key.
188526
+ this._nameIndex = Object.create(null);
188353
188527
  }
188354
188528
  function _findNodeIndex(list,node){
188355
188529
  var i = list.length;
@@ -188358,12 +188532,27 @@ function requireDom () {
188358
188532
  }
188359
188533
  }
188360
188534
 
188535
+ function _nnmIndexAdd(list, attr) {
188536
+ list._nameIndex[attr.nodeName] = attr;
188537
+ }
188538
+ function _nnmIndexRemove(list, attr) {
188539
+ // Only drop the entry if it still points at this attribute; a replacement with
188540
+ // a different nodeName may already have re-keyed it.
188541
+ if (list._nameIndex[attr.nodeName] === attr) {
188542
+ delete list._nameIndex[attr.nodeName];
188543
+ }
188544
+ }
188545
+
188361
188546
  function _addNamedNode(el,list,newAttr,oldAttr){
188362
188547
  if(oldAttr){
188363
188548
  list[_findNodeIndex(list,oldAttr)] = newAttr;
188549
+ // oldAttr leaves the list; drop its index entry (its nodeName may differ
188550
+ // from newAttr's when the replacement came via setNamedItemNS).
188551
+ _nnmIndexRemove(list, oldAttr);
188364
188552
  }else {
188365
188553
  list[list.length++] = newAttr;
188366
188554
  }
188555
+ _nnmIndexAdd(list, newAttr);
188367
188556
  if(el){
188368
188557
  newAttr.ownerElement = el;
188369
188558
  var doc = el.ownerDocument;
@@ -188382,6 +188571,7 @@ function requireDom () {
188382
188571
  list[i] = list[++i];
188383
188572
  }
188384
188573
  list.length = lastIndex;
188574
+ _nnmIndexRemove(list, attr);
188385
188575
  if(el){
188386
188576
  var doc = el.ownerDocument;
188387
188577
  if(doc){
@@ -188415,7 +188605,11 @@ function requireDom () {
188415
188605
  if(el && el!=this._ownerElement){
188416
188606
  throw new DOMException(INUSE_ATTRIBUTE_ERR);
188417
188607
  }
188418
- var oldAttr = this.getNamedItem(attr.nodeName);
188608
+ // Resolve any existing attribute with the same nodeName through the O(1)
188609
+ // membership index rather than an O(M) scan — this is the parse-dedup hot
188610
+ // path (setAttributeNode per attribute during parse). Absent -> undefined,
188611
+ // matching getNamedItem's contract.
188612
+ var oldAttr = this._nameIndex[attr.nodeName];
188419
188613
  _addNamedNode(this._ownerElement,this,attr,oldAttr);
188420
188614
  return oldAttr;
188421
188615
  },
@@ -188648,9 +188842,38 @@ function requireDom () {
188648
188842
  while (child) {
188649
188843
  var next = child.nextSibling;
188650
188844
  if (next !== null && next.nodeType === TEXT_NODE && child.nodeType === TEXT_NODE) {
188651
- node.removeChild(next);
188652
- child.appendData(next.data);
188653
- // Do not advance child: re-check new nextSibling for another text run
188845
+ // Merge the whole run of adjacent text nodes at once: gather the
188846
+ // following text siblings' data, unlink them in a single pass, and
188847
+ // re-index the child list a single time. Per-sibling `removeChild`
188848
+ // (each an O(K) re-index) plus per-sibling `appendData` (each an O(K)
188849
+ // string rebuild) is O(K^2) over a long run of single-character text
188850
+ // nodes; this keeps it O(K). The first text node of the run survives
188851
+ // and carries the concatenated data, preserving node identity and
188852
+ // locator semantics.
188853
+ var tail = [];
188854
+ var sibling = next;
188855
+ while (sibling !== null && sibling.nodeType === TEXT_NODE) {
188856
+ tail.push(sibling.data);
188857
+ sibling = sibling.nextSibling;
188858
+ }
188859
+ // `sibling` is now the first non-text node after the run, or null.
188860
+ var removed = child.nextSibling;
188861
+ while (removed !== sibling) {
188862
+ var following = removed.nextSibling;
188863
+ removed.parentNode = null;
188864
+ removed.previousSibling = null;
188865
+ removed.nextSibling = null;
188866
+ removed = following;
188867
+ }
188868
+ child.nextSibling = sibling;
188869
+ if (sibling !== null) {
188870
+ sibling.previousSibling = child;
188871
+ } else {
188872
+ node.lastChild = child;
188873
+ }
188874
+ child.appendData(tail.join('')); // single O(K) string rebuild
188875
+ _onUpdateChild(node.ownerDocument, node); // single O(K) re-index
188876
+ child = sibling;
188654
188877
  } else {
188655
188878
  child = next;
188656
188879
  }
@@ -189461,8 +189684,10 @@ function requireDom () {
189461
189684
  * - it does not do any input validation on the arguments and doesn't throw "InvalidCharacterError".
189462
189685
  *
189463
189686
  * Note: When the resulting document is serialized with `requireWellFormed: true`, the
189464
- * serializer throws with code `INVALID_STATE_ERR` if `.data` contains `?>` (W3C DOM Parsing
189465
- * §3.2.1.7). Without that option the data is emitted verbatim.
189687
+ * serializer throws with code `INVALID_STATE_ERR` if `.target` is not a valid XML `NCName`
189688
+ * (a `Name` with no colon) or is an ASCII case-insensitive match for `"xml"`, or if `.data`
189689
+ * contains `?>` (W3C DOM Parsing §3.2.1.7). Without that option the target and data are
189690
+ * emitted verbatim.
189466
189691
  *
189467
189692
  * @param {string} target
189468
189693
  * @param {string} data
@@ -189487,7 +189712,27 @@ function requireDom () {
189487
189712
  node.specified = true;
189488
189713
  return node;
189489
189714
  },
189715
+ /**
189716
+ * Creates an EntityReference object, serialized as `&name;`.
189717
+ *
189718
+ * The `name` is validated against the XML `Name` production at creation time; an invalid name
189719
+ * throws a `DOMException` with code `INVALID_CHARACTER_ERR`. When the resulting node is
189720
+ * serialized with `requireWellFormed: true`, the serializer re-validates `nodeName` and throws
189721
+ * a `DOMException` with code `INVALID_STATE_ERR` if a later `nodeName` mutation made it invalid;
189722
+ * without that option the name is emitted verbatim.
189723
+ *
189724
+ * Note: xmldom does not expand entities — the parser resolves entity references inline and never
189725
+ * constructs `EntityReference` nodes, so this method is the only producer.
189726
+ *
189727
+ * @param {string} name The name of the entity to reference.
189728
+ * @returns {EntityReference}
189729
+ * @throws {DOMException} With code `INVALID_CHARACTER_ERR` when `name` is not a valid XML `Name`.
189730
+ * @see https://www.w3.org/TR/DOM-Level-3-Core/core.html#ID-392B75AE
189731
+ */
189490
189732
  createEntityReference : function(name){
189733
+ if (!tagNamePattern.test(name)) {
189734
+ throw new DOMException(INVALID_CHARACTER_ERR, 'not a valid xml name "' + name + '"');
189735
+ }
189491
189736
  var node = new EntityReference();
189492
189737
  node.ownerDocument = this;
189493
189738
  node.nodeName = name;
@@ -189699,15 +189944,16 @@ function requireDom () {
189699
189944
  /**
189700
189945
  * Represents a DocumentType node (the `<!DOCTYPE ...>` declaration).
189701
189946
  *
189702
- * `publicId`, `systemId`, and `internalSubset` are plain own-property assignments.
189947
+ * `name`, `publicId`, `systemId`, and `internalSubset` are plain own-property assignments.
189703
189948
  * xmldom does not enforce the `readonly` constraint declared by the WHATWG DOM spec —
189704
189949
  * direct property writes succeed silently. Values are serialized verbatim when
189705
189950
  * `requireWellFormed` is false (the default). When the serializer is invoked with
189706
189951
  * `requireWellFormed: true` (via the 4th-parameter options object), it validates each
189707
- * field and throws `DOMException` with code `INVALID_STATE_ERR` on invalid values.
189952
+ * field — including `name`, which is checked against the XML `Name` production — and throws
189953
+ * `DOMException` with code `INVALID_STATE_ERR` on invalid values.
189708
189954
  *
189709
189955
  * @class
189710
- * @see https://developer.mozilla.org/en-US/docs/Web/API/DocumentType MDN
189956
+ * @see https://developer.mozilla.org/docs/Web/API/DocumentType MDN
189711
189957
  */
189712
189958
  function DocumentType() {
189713
189959
  } DocumentType.prototype.nodeType = DOCUMENT_TYPE_NODE;
@@ -189721,6 +189967,20 @@ function requireDom () {
189721
189967
  } Entity.prototype.nodeType = ENTITY_NODE;
189722
189968
  _extends(Entity,Node);
189723
189969
 
189970
+ /**
189971
+ * Represents an EntityReference node, serialized as `&nodeName;`.
189972
+ *
189973
+ * `nodeName` is the referenced entity's name, stored verbatim. When serialized with
189974
+ * `requireWellFormed: true`, the serializer validates `nodeName` against the XML `Name` production
189975
+ * and throws a `DOMException` with code `INVALID_STATE_ERR` if it does not match; without that
189976
+ * option the name is emitted verbatim between `&` and `;`.
189977
+ *
189978
+ * Note: xmldom does not expand entities — the parser resolves entity references inline and never
189979
+ * constructs `EntityReference` nodes, so the only producer is `Document.createEntityReference`.
189980
+ *
189981
+ * @class
189982
+ * @see https://www.w3.org/TR/xml/#NT-Name
189983
+ */
189724
189984
  function EntityReference() {
189725
189985
  } EntityReference.prototype.nodeType = ENTITY_REFERENCE_NODE;
189726
189986
  _extends(EntityReference,Node);
@@ -189758,14 +190018,20 @@ function requireDom () {
189758
190018
  * @returns {string}
189759
190019
  * @throws {DOMException}
189760
190020
  * With code `INVALID_STATE_ERR` when `requireWellFormed` is `true` and:
190021
+ * - an Element's qualified name (including any namespace prefix) is not a valid XML QName,
190022
+ * - an attribute's qualified name (including a synthesized `xmlns:` namespace declaration) is
190023
+ * not a valid XML QName,
189761
190024
  * - a CDATASection node's data contains `"]]>"`,
189762
190025
  * - a Comment node's data contains `"-->"` (bare `"--"` does not throw on this branch),
189763
- * - a ProcessingInstruction's data contains `"?>"`,
190026
+ * - a ProcessingInstruction's target is not a valid XML `NCName` (a `Name` with no colon) or is
190027
+ * an ASCII case-insensitive match for `"xml"`, or its data contains `"?>"`,
190028
+ * - a DocumentType's `name` is not a valid XML `Name` (XML 1.0 production [5]),
189764
190029
  * - a DocumentType's `publicId` is non-empty and does not match the XML `PubidLiteral`
189765
190030
  * production,
189766
190031
  * - a DocumentType's `systemId` is non-empty and does not match the XML `SystemLiteral`
189767
- * production, or
189768
- * - a DocumentType's `internalSubset` contains `"]>"`.
190032
+ * production,
190033
+ * - a DocumentType's `internalSubset` contains `"]>"`, or
190034
+ * - an EntityReference's `nodeName` is not a valid XML `Name` (XML 1.0 production [5]).
189769
190035
  * Note: xmldom does not enforce `readonly` on DocumentType fields — direct property
189770
190036
  * writes succeed and are covered by the serializer-level checks above.
189771
190037
  * @see https://html.spec.whatwg.org/#dom-xmlserializer-serializetostring
@@ -189839,7 +190105,10 @@ function requireDom () {
189839
190105
  * @see https://www.w3.org/TR/xml11/#AVNormalize
189840
190106
  * @see https://w3c.github.io/DOM-Parsing/#serializing-an-element-s-attributes
189841
190107
  */
189842
- function addSerializedAttribute(buf, qualifiedName, value) {
190108
+ function addSerializedAttribute(buf, qualifiedName, value, requireWellFormed) {
190109
+ if (requireWellFormed && !tagNamePattern.test(qualifiedName)) {
190110
+ throw new DOMException(INVALID_STATE_ERR, 'The attribute name "' + qualifiedName + '" is not a valid XML QName');
190111
+ }
189843
190112
  buf.push(' ', qualifiedName, '="', value.replace(/[<>&"\t\n\r]/g, _xmlEncoder), '"');
189844
190113
  }
189845
190114
 
@@ -189905,6 +190174,9 @@ function requireDom () {
189905
190174
  }
189906
190175
  }
189907
190176
 
190177
+ if (requireWellFormed && !tagNamePattern.test(prefixedNodeName)) {
190178
+ throw new DOMException(INVALID_STATE_ERR, 'The element name "' + prefixedNodeName + '" is not a valid XML QName');
190179
+ }
189908
190180
  buf.push('<', prefixedNodeName);
189909
190181
 
189910
190182
  // Build a fresh namespace snapshot for this element's children.
@@ -189924,7 +190196,7 @@ function requireDom () {
189924
190196
  if (needNamespaceDefine(attr, html, childNs)) {
189925
190197
  var attrPrefix = attr.prefix || '';
189926
190198
  var uri = attr.namespaceURI;
189927
- addSerializedAttribute(buf, attrPrefix ? 'xmlns:' + attrPrefix : 'xmlns', uri);
190199
+ addSerializedAttribute(buf, attrPrefix ? 'xmlns:' + attrPrefix : 'xmlns', uri, requireWellFormed);
189928
190200
  childNs.push({ prefix: attrPrefix, namespace: uri });
189929
190201
  }
189930
190202
  // Apply nodeFilter and serialize the attribute.
@@ -189933,7 +190205,7 @@ function requireDom () {
189933
190205
  if (typeof filteredAttr === 'string') {
189934
190206
  buf.push(filteredAttr);
189935
190207
  } else {
189936
- addSerializedAttribute(buf, filteredAttr.name, filteredAttr.value);
190208
+ addSerializedAttribute(buf, filteredAttr.name, filteredAttr.value, requireWellFormed);
189937
190209
  }
189938
190210
  }
189939
190211
  }
@@ -189942,7 +190214,7 @@ function requireDom () {
189942
190214
  if (nodeName === prefixedNodeName && needNamespaceDefine(n, html, childNs)) {
189943
190215
  var nodePrefix = n.prefix || '';
189944
190216
  var uri = n.namespaceURI;
189945
- addSerializedAttribute(buf, nodePrefix ? 'xmlns:' + nodePrefix : 'xmlns', uri);
190217
+ addSerializedAttribute(buf, nodePrefix ? 'xmlns:' + nodePrefix : 'xmlns', uri, requireWellFormed);
189946
190218
  childNs.push({ prefix: nodePrefix, namespace: uri });
189947
190219
  }
189948
190220
 
@@ -189975,7 +190247,7 @@ function requireDom () {
189975
190247
  return { ns: ns.slice(), isHTML: html, tag: null };
189976
190248
 
189977
190249
  case ATTRIBUTE_NODE:
189978
- addSerializedAttribute(buf, n.name, n.value);
190250
+ addSerializedAttribute(buf, n.name, n.value, requireWellFormed);
189979
190251
  return null;
189980
190252
 
189981
190253
  case TEXT_NODE:
@@ -190014,6 +190286,9 @@ function requireDom () {
190014
190286
 
190015
190287
  case DOCUMENT_TYPE_NODE:
190016
190288
  if (requireWellFormed) {
190289
+ if (!tagNamePattern.test(n.name)) {
190290
+ throw new DOMException(INVALID_STATE_ERR, 'The doctype name "' + n.name + '" is not a valid XML Name');
190291
+ }
190017
190292
  if (n.publicId && !/^("[\x20\r\na-zA-Z0-9\-()+,.\/:=?;!*#@$_%']*"|'[\x20\r\na-zA-Z0-9\-()+,.\/:=?;!*#@$_%'"]*')$/.test(n.publicId)) {
190018
190293
  throw new DOMException(INVALID_STATE_ERR, 'DocumentType publicId is not a valid PubidLiteral');
190019
190294
  }
@@ -190045,13 +190320,27 @@ function requireDom () {
190045
190320
  return null;
190046
190321
 
190047
190322
  case PROCESSING_INSTRUCTION_NODE:
190048
- if (requireWellFormed && n.data.indexOf('?>') !== -1) {
190049
- throw new DOMException(INVALID_STATE_ERR, 'The ProcessingInstruction data contains "?>"');
190323
+ if (requireWellFormed) {
190324
+ if (!tagNamePattern.test(n.target) || n.target.indexOf(':') !== -1 || n.target.toLowerCase() === 'xml') {
190325
+ throw new DOMException(
190326
+ INVALID_STATE_ERR,
190327
+ 'The processing instruction target "' + n.target + '" is not a valid XML NCName or is reserved'
190328
+ );
190329
+ }
190330
+ if (n.data.indexOf('?>') !== -1) {
190331
+ throw new DOMException(INVALID_STATE_ERR, 'The ProcessingInstruction data contains "?>"');
190332
+ }
190050
190333
  }
190051
190334
  buf.push('<?', n.target, ' ', n.data, '?>');
190052
190335
  return null;
190053
190336
 
190054
190337
  case ENTITY_REFERENCE_NODE:
190338
+ if (requireWellFormed && !tagNamePattern.test(n.nodeName)) {
190339
+ throw new DOMException(
190340
+ INVALID_STATE_ERR,
190341
+ 'The entity reference name "' + n.nodeName + '" is not a valid XML Name'
190342
+ );
190343
+ }
190055
190344
  buf.push('&', n.nodeName, ';');
190056
190345
  return null;
190057
190346
 
@@ -192432,14 +192721,8 @@ function requireSax () {
192432
192721
  if (hasRequiredSax) return sax;
192433
192722
  hasRequiredSax = 1;
192434
192723
  var NAMESPACE = requireConventions().NAMESPACE;
192724
+ var tagNamePattern = requireConventions().tagNamePattern;
192435
192725
 
192436
- //[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]
192437
- //[4a] NameChar ::= NameStartChar | "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] | [#x203F-#x2040]
192438
- //[5] Name ::= NameStartChar (NameChar)*
192439
- 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
192440
- var nameChar = new RegExp("[\\-\\.0-9"+nameStartChar.source.slice(1,-1)+"\\u00B7\\u0300-\\u036F\\u203F-\\u2040]");
192441
- var tagNamePattern = new RegExp('^'+nameStartChar.source+nameChar.source+'*(?:\:'+nameStartChar.source+nameChar.source+'*)?$');
192442
- //var tagNamePattern = /^[a-zA-Z_][\w\-\.]*(?:\:[a-zA-Z_][\w\-\.]*)?$/
192443
192726
  //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(',')
192444
192727
 
192445
192728
  //S_TAG, S_ATTR, S_EQ, S_ATTR_NOQUOT_VALUE
@@ -192550,7 +192833,13 @@ function requireSax () {
192550
192833
  switch(source.charAt(tagStart+1)){
192551
192834
  case '/':
192552
192835
  var end = source.indexOf('>',tagStart+3);
192553
- var tagName = source.substring(tagStart + 2, end).replace(/[ \t\n\r]+$/g, '');
192836
+ // Anchored trailing-whitespace trim. The former `/[ \t\n\r]+$/g` backtracked
192837
+ // quadratically on a name shaped `whitespace-run + non-whitespace char`
192838
+ // (an end tag `</ … x>`): from every start position it extended `[ws]+`
192839
+ // to the end and then failed the `$` anchor. This anchored form matches the
192840
+ // whole string once and captures everything up to the last non-whitespace
192841
+ // character, so it trims in linear time with byte-identical output.
192842
+ var tagName = source.substring(tagStart + 2, end).replace(/^([\s\S]*?[^ \t\n\r])?[ \t\n\r]*$/, '$1');
192554
192843
  var config = parseStack.pop();
192555
192844
  if(end<0){
192556
192845
 
@@ -192561,6 +192850,14 @@ function requireSax () {
192561
192850
  tagName = tagName.replace(/[\s<].*/,'');
192562
192851
  errorHandler.error("end tag name: "+tagName+' maybe not complete');
192563
192852
  end = tagStart+1+tagName.length;
192853
+ }else if(/[ \t\n\r]/.test(tagName) && tagNamePattern.test(tagName.split(/[ \t\n\r]/)[0])){
192854
+ // The XML `ETag` production is `'</' Name S? '>'`: only optional whitespace may follow
192855
+ // the `Name`. A valid `Name` followed by whitespace and non-whitespace residue (e.g.
192856
+ // `</a\nbogus>` or `</a bogus>`) is not well-formed, but historically it was silently
192857
+ // accepted (the malformed end tag ignored, the residue dropped, the element left on the
192858
+ // stack). Report it as a recoverable `error` (which a custom errorHandler may escalate to
192859
+ // fatal) while keeping the existing recovery so the parsed DOM stays byte-identical.
192860
+ errorHandler.error('end tag name is followed by whitespace and trailing content: "'+tagName+'"');
192564
192861
  }
192565
192862
  var localNSMap = config.localNSMap;
192566
192863
  var endMatch = config.tagName == tagName;
@@ -192684,6 +192981,15 @@ function requireSax () {
192684
192981
  var s = S_TAG;//status
192685
192982
  while(true){
192686
192983
  var c = source.charAt(p);
192984
+ if (s === S_TAG && c === '<') {
192985
+ // A `<` can never occur inside a tag name. Without this guard the scan runs
192986
+ // on to the next `>` (or EOF) before the tag name is rejected, so a document
192987
+ // with many `<` inside a malformed tag makes each one-character recovery step
192988
+ // re-scan to the distant `>` — O(n^2). Stopping at the `<` keeps each recovery
192989
+ // step bounded. The candidate scanned so far is reported raw, consistent with
192990
+ // the sibling invalid-tag-name throw below.
192991
+ throw new Error('unexpected < in tag name: ' + source.slice(start, p));
192992
+ }
192687
192993
  switch(c){
192688
192994
  case '=':
192689
192995
  if(s === S_ATTR){//attrName
@@ -192876,9 +193182,13 @@ function requireSax () {
192876
193182
  if(nsPrefix !== false){//hack!!
192877
193183
  if(localNSMap == null){
192878
193184
  localNSMap = {};
192879
- //console.log(currentNSMap,0)
192880
- _copy(currentNSMap,currentNSMap={});
192881
- //console.log(currentNSMap,1)
193185
+ // Derive the child scope's namespace map by prototype-chain inheritance
193186
+ // instead of a flat copy: lookups inherit ancestor prefixes transparently,
193187
+ // so a document nesting N scopes retains O(N) map entries rather than
193188
+ // sum(1..N) = O(N^2). localNSMap stays a flat own-only record of the
193189
+ // prefixes declared at THIS element, so own-property enumeration
193190
+ // (endPrefixMapping below) still reports only local declarations.
193191
+ currentNSMap = Object.create(currentNSMap);
192882
193192
  }
192883
193193
  currentNSMap[nsPrefix] = localNSMap[nsPrefix] = value;
192884
193194
  a.uri = NAMESPACE.XMLNS;