@dan-uni/dan-any 1.4.4 → 1.4.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13573,14 +13573,14 @@
13573
13573
  "use strict";
13574
13574
  __webpack_require__.r(__webpack_exports__);
13575
13575
  __webpack_require__.d(__webpack_exports__, {
13576
- UniDM: ()=>UniDM,
13577
- UniPool: ()=>UniPool,
13578
13576
  DM_format: ()=>src_DM_format,
13579
- plugins: ()=>plugins,
13580
- platform: ()=>platform,
13577
+ UniDM: ()=>UniDM,
13581
13578
  UniDMTools: ()=>dm_gen_namespaceObject,
13579
+ UniIDTools: ()=>id_gen_namespaceObject,
13580
+ UniPool: ()=>UniPool,
13582
13581
  convert2Formats: ()=>convert2Formats,
13583
- UniIDTools: ()=>id_gen_namespaceObject
13582
+ platform: ()=>platform,
13583
+ plugins: ()=>plugins
13584
13584
  });
13585
13585
  var id_gen_namespaceObject = {};
13586
13586
  __webpack_require__.r(id_gen_namespaceObject);
@@ -14016,6 +14016,7 @@
14016
14016
  unpairedTags: [],
14017
14017
  processEntities: true,
14018
14018
  htmlEntities: false,
14019
+ entityDecoder: null,
14019
14020
  ignoreDeclaration: false,
14020
14021
  ignorePiTags: false,
14021
14022
  transformTagName: false,
@@ -14035,16 +14036,17 @@
14035
14036
  if (DANGEROUS_PROPERTY_NAMES.some((dangerous)=>normalized === dangerous.toLowerCase())) throw new Error(`[SECURITY] Invalid ${optionName}: "${propertyName}" is a reserved JavaScript keyword that could cause prototype pollution`);
14036
14037
  if (criticalProperties.some((dangerous)=>normalized === dangerous.toLowerCase())) throw new Error(`[SECURITY] Invalid ${optionName}: "${propertyName}" is a reserved JavaScript keyword that could cause prototype pollution`);
14037
14038
  }
14038
- function normalizeProcessEntities(value) {
14039
+ function normalizeProcessEntities(value, htmlEntities) {
14039
14040
  if ('boolean' == typeof value) return {
14040
14041
  enabled: value,
14041
14042
  maxEntitySize: 10000,
14042
- maxExpansionDepth: 10,
14043
- maxTotalExpansions: 1000,
14043
+ maxExpansionDepth: 10000,
14044
+ maxTotalExpansions: 1 / 0,
14044
14045
  maxExpandedLength: 100000,
14045
- maxEntityCount: 100,
14046
+ maxEntityCount: 1000,
14046
14047
  allowedTags: null,
14047
- tagFilter: null
14048
+ tagFilter: null,
14049
+ appliesTo: "all"
14048
14050
  };
14049
14051
  if ('object' == typeof value && null !== value) return {
14050
14052
  enabled: false !== value.enabled,
@@ -14054,7 +14056,8 @@
14054
14056
  maxExpandedLength: Math.max(1, value.maxExpandedLength ?? 100000),
14055
14057
  maxEntityCount: Math.max(1, value.maxEntityCount ?? 1000),
14056
14058
  allowedTags: value.allowedTags ?? null,
14057
- tagFilter: value.tagFilter ?? null
14059
+ tagFilter: value.tagFilter ?? null,
14060
+ appliesTo: value.appliesTo ?? "all"
14058
14061
  };
14059
14062
  return normalizeProcessEntities(true);
14060
14063
  }
@@ -14084,7 +14087,7 @@
14084
14087
  ];
14085
14088
  for (const { value, name } of propertyNameOptions)if (value) validatePropertyName(value, name);
14086
14089
  if (null === built.onDangerousProperty) built.onDangerousProperty = defaultOnDangerousProperty;
14087
- built.processEntities = normalizeProcessEntities(built.processEntities);
14090
+ built.processEntities = normalizeProcessEntities(built.processEntities, built.htmlEntities);
14088
14091
  built.unpairedTagsSet = new Set(built.unpairedTags);
14089
14092
  if (built.stopNodes && Array.isArray(built.stopNodes)) built.stopNodes = built.stopNodes.map((node)=>{
14090
14093
  if ('string' == typeof node && node.startsWith('*.')) return '..' + node.substring(2);
@@ -14152,11 +14155,7 @@
14152
14155
  [entityName, val, i] = this.readEntityExp(xmlData, i + 1, this.suppressValidationErr);
14153
14156
  if (-1 === val.indexOf("&")) {
14154
14157
  if (false !== this.options.enabled && null != this.options.maxEntityCount && entityCount >= this.options.maxEntityCount) throw new Error(`Entity count (${entityCount + 1}) exceeds maximum allowed (${this.options.maxEntityCount})`);
14155
- const escaped = entityName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
14156
- entities[entityName] = {
14157
- regx: RegExp(`&${escaped};`, "g"),
14158
- val: val
14159
- };
14158
+ entities[entityName] = val;
14160
14159
  entityCount++;
14161
14160
  }
14162
14161
  } else if (hasBody && hasSeq(xmlData, "!ELEMENT", i)) {
@@ -14845,6 +14844,1333 @@
14845
14844
  return null;
14846
14845
  }
14847
14846
  }
14847
+ const BASIC_LATIN = {
14848
+ amp: '&',
14849
+ AMP: '&',
14850
+ lt: '<',
14851
+ LT: '<',
14852
+ gt: '>',
14853
+ GT: '>',
14854
+ quot: '"',
14855
+ QUOT: '"',
14856
+ apos: "'",
14857
+ lsquo: '‘',
14858
+ rsquo: '’',
14859
+ ldquo: '“',
14860
+ rdquo: '”',
14861
+ lsquor: '‚',
14862
+ rsquor: '’',
14863
+ ldquor: '„',
14864
+ bdquo: '„',
14865
+ comma: ',',
14866
+ period: '.',
14867
+ colon: ':',
14868
+ semi: ';',
14869
+ excl: '!',
14870
+ quest: '?',
14871
+ num: '#',
14872
+ dollar: '$',
14873
+ percent: '%',
14874
+ amp: '&',
14875
+ ast: '*',
14876
+ commat: '@',
14877
+ lowbar: '_',
14878
+ verbar: '|',
14879
+ vert: '|',
14880
+ sol: '/',
14881
+ bsol: '\\',
14882
+ lbrace: '{',
14883
+ rbrace: '}',
14884
+ lbrack: '[',
14885
+ rbrack: ']',
14886
+ lpar: '(',
14887
+ rpar: ')',
14888
+ nbsp: '\u00a0',
14889
+ iexcl: '¡',
14890
+ cent: '¢',
14891
+ pound: '£',
14892
+ curren: '¤',
14893
+ yen: '¥',
14894
+ brvbar: '¦',
14895
+ sect: '§',
14896
+ uml: '¨',
14897
+ copy: '©',
14898
+ COPY: '©',
14899
+ ordf: 'ª',
14900
+ laquo: '«',
14901
+ not: '¬',
14902
+ shy: '\u00ad',
14903
+ reg: '®',
14904
+ REG: '®',
14905
+ macr: '¯',
14906
+ deg: '°',
14907
+ plusmn: '±',
14908
+ sup2: '²',
14909
+ sup3: '³',
14910
+ acute: '´',
14911
+ micro: 'µ',
14912
+ para: '¶',
14913
+ middot: '·',
14914
+ cedil: '¸',
14915
+ sup1: '¹',
14916
+ ordm: 'º',
14917
+ raquo: '»',
14918
+ frac14: '¼',
14919
+ frac12: '½',
14920
+ half: '½',
14921
+ frac34: '¾',
14922
+ iquest: '¿',
14923
+ times: '×',
14924
+ div: '÷',
14925
+ divide: '÷'
14926
+ };
14927
+ const LATIN_ACCENTS = {
14928
+ Agrave: 'À',
14929
+ agrave: 'à',
14930
+ Aacute: 'Á',
14931
+ aacute: 'á',
14932
+ Acirc: 'Â',
14933
+ acirc: 'â',
14934
+ Atilde: 'Ã',
14935
+ atilde: 'ã',
14936
+ Auml: 'Ä',
14937
+ auml: 'ä',
14938
+ Aring: 'Å',
14939
+ aring: 'å',
14940
+ AElig: 'Æ',
14941
+ aelig: 'æ',
14942
+ Ccedil: 'Ç',
14943
+ ccedil: 'ç',
14944
+ Egrave: 'È',
14945
+ egrave: 'è',
14946
+ Eacute: 'É',
14947
+ eacute: 'é',
14948
+ Ecirc: 'Ê',
14949
+ ecirc: 'ê',
14950
+ Euml: 'Ë',
14951
+ euml: 'ë',
14952
+ Igrave: 'Ì',
14953
+ igrave: 'ì',
14954
+ Iacute: 'Í',
14955
+ iacute: 'í',
14956
+ Icirc: 'Î',
14957
+ icirc: 'î',
14958
+ Iuml: 'Ï',
14959
+ iuml: 'ï',
14960
+ ETH: 'Ð',
14961
+ eth: 'ð',
14962
+ Ntilde: 'Ñ',
14963
+ ntilde: 'ñ',
14964
+ Ograve: 'Ò',
14965
+ ograve: 'ò',
14966
+ Oacute: 'Ó',
14967
+ oacute: 'ó',
14968
+ Ocirc: 'Ô',
14969
+ ocirc: 'ô',
14970
+ Otilde: 'Õ',
14971
+ otilde: 'õ',
14972
+ Ouml: 'Ö',
14973
+ ouml: 'ö',
14974
+ Oslash: 'Ø',
14975
+ oslash: 'ø',
14976
+ Ugrave: 'Ù',
14977
+ ugrave: 'ù',
14978
+ Uacute: 'Ú',
14979
+ uacute: 'ú',
14980
+ Ucirc: 'Û',
14981
+ ucirc: 'û',
14982
+ Uuml: 'Ü',
14983
+ uuml: 'ü',
14984
+ Yacute: 'Ý',
14985
+ yacute: 'ý',
14986
+ THORN: 'Þ',
14987
+ thorn: 'þ',
14988
+ szlig: 'ß',
14989
+ yuml: 'ÿ',
14990
+ Yuml: 'Ÿ'
14991
+ };
14992
+ const LATIN_EXTENDED = {
14993
+ Amacr: 'Ā',
14994
+ amacr: 'ā',
14995
+ Abreve: 'Ă',
14996
+ abreve: 'ă',
14997
+ Aogon: 'Ą',
14998
+ aogon: 'ą',
14999
+ Cacute: 'Ć',
15000
+ cacute: 'ć',
15001
+ Ccirc: 'Ĉ',
15002
+ ccirc: 'ĉ',
15003
+ Cdot: 'Ċ',
15004
+ cdot: 'ċ',
15005
+ Ccaron: 'Č',
15006
+ ccaron: 'č',
15007
+ Dcaron: 'Ď',
15008
+ dcaron: 'ď',
15009
+ Dstrok: 'Đ',
15010
+ dstrok: 'đ',
15011
+ Emacr: 'Ē',
15012
+ emacr: 'ē',
15013
+ Ecaron: 'Ě',
15014
+ ecaron: 'ě',
15015
+ Edot: 'Ė',
15016
+ edot: 'ė',
15017
+ Eogon: 'Ę',
15018
+ eogon: 'ę',
15019
+ Gcirc: 'Ĝ',
15020
+ gcirc: 'ĝ',
15021
+ Gbreve: 'Ğ',
15022
+ gbreve: 'ğ',
15023
+ Gdot: 'Ġ',
15024
+ gdot: 'ġ',
15025
+ Gcedil: 'Ģ',
15026
+ Hcirc: 'Ĥ',
15027
+ hcirc: 'ĥ',
15028
+ Hstrok: 'Ħ',
15029
+ hstrok: 'ħ',
15030
+ Itilde: 'Ĩ',
15031
+ itilde: 'ĩ',
15032
+ Imacr: 'Ī',
15033
+ imacr: 'ī',
15034
+ Iogon: 'Į',
15035
+ iogon: 'į',
15036
+ Idot: 'İ',
15037
+ IJlig: 'IJ',
15038
+ ijlig: 'ij',
15039
+ Jcirc: 'Ĵ',
15040
+ jcirc: 'ĵ',
15041
+ Kcedil: 'Ķ',
15042
+ kcedil: 'ķ',
15043
+ kgreen: 'ĸ',
15044
+ Lacute: 'Ĺ',
15045
+ lacute: 'ĺ',
15046
+ Lcedil: 'Ļ',
15047
+ lcedil: 'ļ',
15048
+ Lcaron: 'Ľ',
15049
+ lcaron: 'ľ',
15050
+ Lmidot: 'Ŀ',
15051
+ lmidot: 'ŀ',
15052
+ Lstrok: 'Ł',
15053
+ lstrok: 'ł',
15054
+ Nacute: 'Ń',
15055
+ nacute: 'ń',
15056
+ Ncaron: 'Ň',
15057
+ ncaron: 'ň',
15058
+ Ncedil: 'Ņ',
15059
+ ncedil: 'ņ',
15060
+ ENG: 'Ŋ',
15061
+ eng: 'ŋ',
15062
+ Omacr: 'Ō',
15063
+ omacr: 'ō',
15064
+ Odblac: 'Ő',
15065
+ odblac: 'ő',
15066
+ OElig: 'Œ',
15067
+ oelig: 'œ',
15068
+ Racute: 'Ŕ',
15069
+ racute: 'ŕ',
15070
+ Rcaron: 'Ř',
15071
+ rcaron: 'ř',
15072
+ Rcedil: 'Ŗ',
15073
+ rcedil: 'ŗ',
15074
+ Sacute: 'Ś',
15075
+ sacute: 'ś',
15076
+ Scirc: 'Ŝ',
15077
+ scirc: 'ŝ',
15078
+ Scedil: 'Ş',
15079
+ scedil: 'ş',
15080
+ Scaron: 'Š',
15081
+ scaron: 'š',
15082
+ Tcedil: 'Ţ',
15083
+ tcedil: 'ţ',
15084
+ Tcaron: 'Ť',
15085
+ tcaron: 'ť',
15086
+ Tstrok: 'Ŧ',
15087
+ tstrok: 'ŧ',
15088
+ Utilde: 'Ũ',
15089
+ utilde: 'ũ',
15090
+ Umacr: 'Ū',
15091
+ umacr: 'ū',
15092
+ Ubreve: 'Ŭ',
15093
+ ubreve: 'ŭ',
15094
+ Uring: 'Ů',
15095
+ uring: 'ů',
15096
+ Udblac: 'Ű',
15097
+ udblac: 'ű',
15098
+ Uogon: 'Ų',
15099
+ uogon: 'ų',
15100
+ Wcirc: 'Ŵ',
15101
+ wcirc: 'ŵ',
15102
+ Ycirc: 'Ŷ',
15103
+ ycirc: 'ŷ',
15104
+ Zacute: 'Ź',
15105
+ zacute: 'ź',
15106
+ Zdot: 'Ż',
15107
+ zdot: 'ż',
15108
+ Zcaron: 'Ž',
15109
+ zcaron: 'ž'
15110
+ };
15111
+ const GREEK = {
15112
+ Alpha: 'Α',
15113
+ alpha: 'α',
15114
+ Beta: 'Β',
15115
+ beta: 'β',
15116
+ Gamma: 'Γ',
15117
+ gamma: 'γ',
15118
+ Delta: 'Δ',
15119
+ delta: 'δ',
15120
+ Epsilon: 'Ε',
15121
+ epsilon: 'ε',
15122
+ epsiv: 'ϵ',
15123
+ varepsilon: 'ϵ',
15124
+ Zeta: 'Ζ',
15125
+ zeta: 'ζ',
15126
+ Eta: 'Η',
15127
+ eta: 'η',
15128
+ Theta: 'Θ',
15129
+ theta: 'θ',
15130
+ thetasym: 'ϑ',
15131
+ vartheta: 'ϑ',
15132
+ Iota: 'Ι',
15133
+ iota: 'ι',
15134
+ Kappa: 'Κ',
15135
+ kappa: 'κ',
15136
+ kappav: 'ϰ',
15137
+ varkappa: 'ϰ',
15138
+ Lambda: 'Λ',
15139
+ lambda: 'λ',
15140
+ Mu: 'Μ',
15141
+ mu: 'μ',
15142
+ Nu: 'Ν',
15143
+ nu: 'ν',
15144
+ Xi: 'Ξ',
15145
+ xi: 'ξ',
15146
+ Omicron: 'Ο',
15147
+ omicron: 'ο',
15148
+ Pi: 'Π',
15149
+ pi: 'π',
15150
+ piv: 'ϖ',
15151
+ varpi: 'ϖ',
15152
+ Rho: 'Ρ',
15153
+ rho: 'ρ',
15154
+ rhov: 'ϱ',
15155
+ varrho: 'ϱ',
15156
+ Sigma: 'Σ',
15157
+ sigma: 'σ',
15158
+ sigmaf: 'ς',
15159
+ sigmav: 'ς',
15160
+ varsigma: 'ς',
15161
+ Tau: 'Τ',
15162
+ tau: 'τ',
15163
+ Upsilon: 'Υ',
15164
+ upsilon: 'υ',
15165
+ upsi: 'υ',
15166
+ Upsi: 'ϒ',
15167
+ upsih: 'ϒ',
15168
+ Phi: 'Φ',
15169
+ phi: 'φ',
15170
+ phiv: 'ϕ',
15171
+ varphi: 'ϕ',
15172
+ Chi: 'Χ',
15173
+ chi: 'χ',
15174
+ Psi: 'Ψ',
15175
+ psi: 'ψ',
15176
+ Omega: 'Ω',
15177
+ omega: 'ω',
15178
+ ohm: 'Ω',
15179
+ Gammad: 'Ϝ',
15180
+ gammad: 'ϝ',
15181
+ digamma: 'ϝ'
15182
+ };
15183
+ const CYRILLIC = {
15184
+ Afr: '𝔄',
15185
+ afr: '𝔞',
15186
+ Acy: 'А',
15187
+ acy: 'а',
15188
+ Bcy: 'Б',
15189
+ bcy: 'б',
15190
+ Vcy: 'В',
15191
+ vcy: 'в',
15192
+ Gcy: 'Г',
15193
+ gcy: 'г',
15194
+ Dcy: 'Д',
15195
+ dcy: 'д',
15196
+ IEcy: 'Е',
15197
+ iecy: 'е',
15198
+ IOcy: 'Ё',
15199
+ iocy: 'ё',
15200
+ ZHcy: 'Ж',
15201
+ zhcy: 'ж',
15202
+ Zcy: 'З',
15203
+ zcy: 'з',
15204
+ Icy: 'И',
15205
+ icy: 'и',
15206
+ Jcy: 'Й',
15207
+ jcy: 'й',
15208
+ Kcy: 'К',
15209
+ kcy: 'к',
15210
+ Lcy: 'Л',
15211
+ lcy: 'л',
15212
+ Mcy: 'М',
15213
+ mcy: 'м',
15214
+ Ncy: 'Н',
15215
+ ncy: 'н',
15216
+ Ocy: 'О',
15217
+ ocy: 'о',
15218
+ Pcy: 'П',
15219
+ pcy: 'п',
15220
+ Rcy: 'Р',
15221
+ rcy: 'р',
15222
+ Scy: 'С',
15223
+ scy: 'с',
15224
+ Tcy: 'Т',
15225
+ tcy: 'т',
15226
+ Ucy: 'У',
15227
+ ucy: 'у',
15228
+ Fcy: 'Ф',
15229
+ fcy: 'ф',
15230
+ KHcy: 'Х',
15231
+ khcy: 'х',
15232
+ TScy: 'Ц',
15233
+ tscy: 'ц',
15234
+ CHcy: 'Ч',
15235
+ chcy: 'ч',
15236
+ SHcy: 'Ш',
15237
+ shcy: 'ш',
15238
+ SHCHcy: 'Щ',
15239
+ shchcy: 'щ',
15240
+ HARDcy: 'Ъ',
15241
+ hardcy: 'ъ',
15242
+ Ycy: 'Ы',
15243
+ ycy: 'ы',
15244
+ SOFTcy: 'Ь',
15245
+ softcy: 'ь',
15246
+ Ecy: 'Э',
15247
+ ecy: 'э',
15248
+ YUcy: 'Ю',
15249
+ yucy: 'ю',
15250
+ YAcy: 'Я',
15251
+ yacy: 'я',
15252
+ DJcy: 'Ђ',
15253
+ djcy: 'ђ',
15254
+ GJcy: 'Ѓ',
15255
+ gjcy: 'ѓ',
15256
+ Jukcy: 'Є',
15257
+ jukcy: 'є',
15258
+ DScy: 'Ѕ',
15259
+ dscy: 'ѕ',
15260
+ Iukcy: 'І',
15261
+ iukcy: 'і',
15262
+ YIcy: 'Ї',
15263
+ yicy: 'ї',
15264
+ Jsercy: 'Ј',
15265
+ jsercy: 'ј',
15266
+ LJcy: 'Љ',
15267
+ ljcy: 'љ',
15268
+ NJcy: 'Њ',
15269
+ njcy: 'њ',
15270
+ TSHcy: 'Ћ',
15271
+ tshcy: 'ћ',
15272
+ KJcy: 'Ќ',
15273
+ kjcy: 'ќ',
15274
+ Ubrcy: 'Ў',
15275
+ ubrcy: 'ў',
15276
+ DZcy: 'Џ',
15277
+ dzcy: 'џ'
15278
+ };
15279
+ const MATH = {
15280
+ plus: '+',
15281
+ minus: '−',
15282
+ mnplus: '∓',
15283
+ mp: '∓',
15284
+ pm: '±',
15285
+ times: '×',
15286
+ div: '÷',
15287
+ divide: '÷',
15288
+ sdot: '⋅',
15289
+ star: '☆',
15290
+ starf: '★',
15291
+ bigstar: '★',
15292
+ lowast: '∗',
15293
+ ast: '*',
15294
+ midast: '*',
15295
+ compfn: '∘',
15296
+ smallcircle: '∘',
15297
+ bullet: '•',
15298
+ bull: '•',
15299
+ nbsp: '\u00a0',
15300
+ hellip: '…',
15301
+ mldr: '…',
15302
+ prime: '′',
15303
+ Prime: '″',
15304
+ tprime: '‴',
15305
+ bprime: '‵',
15306
+ backprime: '‵',
15307
+ minus: '−',
15308
+ minusd: '∸',
15309
+ dotminus: '∸',
15310
+ plusdo: '∔',
15311
+ dotplus: '∔',
15312
+ plusmn: '±',
15313
+ minusplus: '∓',
15314
+ mnplus: '∓',
15315
+ mp: '∓',
15316
+ setminus: '∖',
15317
+ smallsetminus: '∖',
15318
+ Backslash: '∖',
15319
+ setmn: '∖',
15320
+ ssetmn: '∖',
15321
+ lowbar: '_',
15322
+ verbar: '|',
15323
+ vert: '|',
15324
+ VerticalLine: '|',
15325
+ colon: ':',
15326
+ Colon: '∷',
15327
+ Proportion: '∷',
15328
+ ratio: '∶',
15329
+ equals: '=',
15330
+ ne: '≠',
15331
+ nequiv: '≢',
15332
+ equiv: '≡',
15333
+ Congruent: '≡',
15334
+ sim: '∼',
15335
+ thicksim: '∼',
15336
+ thksim: '∼',
15337
+ sime: '≃',
15338
+ simeq: '≃',
15339
+ TildeEqual: '≃',
15340
+ asymp: '≈',
15341
+ approx: '≈',
15342
+ thickapprox: '≈',
15343
+ thkap: '≈',
15344
+ TildeTilde: '≈',
15345
+ ncong: '≇',
15346
+ cong: '≅',
15347
+ TildeFullEqual: '≅',
15348
+ asympeq: '≍',
15349
+ CupCap: '≍',
15350
+ bump: '≎',
15351
+ Bumpeq: '≎',
15352
+ HumpDownHump: '≎',
15353
+ bumpe: '≏',
15354
+ bumpeq: '≏',
15355
+ HumpEqual: '≏',
15356
+ dotminus: '∸',
15357
+ minusd: '∸',
15358
+ plusdo: '∔',
15359
+ dotplus: '∔',
15360
+ le: '≤',
15361
+ LessEqual: '≤',
15362
+ ge: '≥',
15363
+ GreaterEqual: '≥',
15364
+ lesseqgtr: '⋚',
15365
+ lesseqqgtr: '⪋',
15366
+ greater: '>',
15367
+ less: '<'
15368
+ };
15369
+ const MATH_ADVANCED = {
15370
+ alefsym: 'ℵ',
15371
+ aleph: 'ℵ',
15372
+ beth: 'ℶ',
15373
+ gimel: 'ℷ',
15374
+ daleth: 'ℸ',
15375
+ forall: '∀',
15376
+ ForAll: '∀',
15377
+ part: '∂',
15378
+ PartialD: '∂',
15379
+ exist: '∃',
15380
+ Exists: '∃',
15381
+ nexist: '∄',
15382
+ nexists: '∄',
15383
+ empty: '∅',
15384
+ emptyset: '∅',
15385
+ emptyv: '∅',
15386
+ varnothing: '∅',
15387
+ nabla: '∇',
15388
+ Del: '∇',
15389
+ isin: '∈',
15390
+ isinv: '∈',
15391
+ in: '∈',
15392
+ Element: '∈',
15393
+ notin: '∉',
15394
+ notinva: '∉',
15395
+ ni: '∋',
15396
+ niv: '∋',
15397
+ SuchThat: '∋',
15398
+ ReverseElement: '∋',
15399
+ notni: '∌',
15400
+ notniva: '∌',
15401
+ prod: '∏',
15402
+ Product: '∏',
15403
+ coprod: '∐',
15404
+ Coproduct: '∐',
15405
+ sum: '∑',
15406
+ Sum: '∑',
15407
+ minus: '−',
15408
+ mp: '∓',
15409
+ plusdo: '∔',
15410
+ dotplus: '∔',
15411
+ setminus: '∖',
15412
+ lowast: '∗',
15413
+ radic: '√',
15414
+ Sqrt: '√',
15415
+ prop: '∝',
15416
+ propto: '∝',
15417
+ Proportional: '∝',
15418
+ varpropto: '∝',
15419
+ infin: '∞',
15420
+ infintie: '⧝',
15421
+ ang: '∠',
15422
+ angle: '∠',
15423
+ angmsd: '∡',
15424
+ measuredangle: '∡',
15425
+ angsph: '∢',
15426
+ mid: '∣',
15427
+ VerticalBar: '∣',
15428
+ nmid: '∤',
15429
+ nsmid: '∤',
15430
+ npar: '∦',
15431
+ parallel: '∥',
15432
+ spar: '∥',
15433
+ nparallel: '∦',
15434
+ nspar: '∦',
15435
+ and: '∧',
15436
+ wedge: '∧',
15437
+ or: '∨',
15438
+ vee: '∨',
15439
+ cap: '∩',
15440
+ cup: '∪',
15441
+ int: '∫',
15442
+ Integral: '∫',
15443
+ conint: '∮',
15444
+ ContourIntegral: '∮',
15445
+ Conint: '∯',
15446
+ DoubleContourIntegral: '∯',
15447
+ Cconint: '∰',
15448
+ there4: '∴',
15449
+ therefore: '∴',
15450
+ Therefore: '∴',
15451
+ becaus: '∵',
15452
+ because: '∵',
15453
+ Because: '∵',
15454
+ ratio: '∶',
15455
+ Proportion: '∷',
15456
+ minusd: '∸',
15457
+ dotminus: '∸',
15458
+ mDDot: '∺',
15459
+ homtht: '∻',
15460
+ sim: '∼',
15461
+ bsimg: '∽',
15462
+ backsim: '∽',
15463
+ ac: '∾',
15464
+ mstpos: '∾',
15465
+ acd: '∿',
15466
+ VerticalTilde: '≀',
15467
+ wr: '≀',
15468
+ wreath: '≀',
15469
+ nsime: '≄',
15470
+ nsimeq: '≄',
15471
+ nsimeq: '≄',
15472
+ ncong: '≇',
15473
+ simne: '≆',
15474
+ ncongdot: '⩭̸',
15475
+ ngsim: '≵',
15476
+ nsim: '≁',
15477
+ napprox: '≉',
15478
+ nap: '≉',
15479
+ ngeq: '≱',
15480
+ nge: '≱',
15481
+ nleq: '≰',
15482
+ nle: '≰',
15483
+ ngtr: '≯',
15484
+ ngt: '≯',
15485
+ nless: '≮',
15486
+ nlt: '≮',
15487
+ nprec: '⊀',
15488
+ npr: '⊀',
15489
+ nsucc: '⊁',
15490
+ nsc: '⊁'
15491
+ };
15492
+ const ARROWS = {
15493
+ larr: '←',
15494
+ leftarrow: '←',
15495
+ LeftArrow: '←',
15496
+ uarr: '↑',
15497
+ uparrow: '↑',
15498
+ UpArrow: '↑',
15499
+ rarr: '→',
15500
+ rightarrow: '→',
15501
+ RightArrow: '→',
15502
+ darr: '↓',
15503
+ downarrow: '↓',
15504
+ DownArrow: '↓',
15505
+ harr: '↔',
15506
+ leftrightarrow: '↔',
15507
+ LeftRightArrow: '↔',
15508
+ varr: '↕',
15509
+ updownarrow: '↕',
15510
+ UpDownArrow: '↕',
15511
+ nwarr: '↖',
15512
+ nwarrow: '↖',
15513
+ UpperLeftArrow: '↖',
15514
+ nearr: '↗',
15515
+ nearrow: '↗',
15516
+ UpperRightArrow: '↗',
15517
+ searr: '↘',
15518
+ searrow: '↘',
15519
+ LowerRightArrow: '↘',
15520
+ swarr: '↙',
15521
+ swarrow: '↙',
15522
+ LowerLeftArrow: '↙',
15523
+ lArr: '⇐',
15524
+ Leftarrow: '⇐',
15525
+ uArr: '⇑',
15526
+ Uparrow: '⇑',
15527
+ rArr: '⇒',
15528
+ Rightarrow: '⇒',
15529
+ dArr: '⇓',
15530
+ Downarrow: '⇓',
15531
+ hArr: '⇔',
15532
+ Leftrightarrow: '⇔',
15533
+ iff: '⇔',
15534
+ vArr: '⇕',
15535
+ Updownarrow: '⇕',
15536
+ lAarr: '⇚',
15537
+ Lleftarrow: '⇚',
15538
+ rAarr: '⇛',
15539
+ Rrightarrow: '⇛',
15540
+ lrarr: '⇆',
15541
+ leftrightarrows: '⇆',
15542
+ rlarr: '⇄',
15543
+ rightleftarrows: '⇄',
15544
+ lrhar: '⇋',
15545
+ leftrightharpoons: '⇋',
15546
+ ReverseEquilibrium: '⇋',
15547
+ rlhar: '⇌',
15548
+ rightleftharpoons: '⇌',
15549
+ Equilibrium: '⇌',
15550
+ udarr: '⇅',
15551
+ UpArrowDownArrow: '⇅',
15552
+ duarr: '⇵',
15553
+ DownArrowUpArrow: '⇵',
15554
+ llarr: '⇇',
15555
+ leftleftarrows: '⇇',
15556
+ rrarr: '⇉',
15557
+ rightrightarrows: '⇉',
15558
+ ddarr: '⇊',
15559
+ downdownarrows: '⇊',
15560
+ har: '↽',
15561
+ lhard: '↽',
15562
+ leftharpoondown: '↽',
15563
+ lharu: '↼',
15564
+ leftharpoonup: '↼',
15565
+ rhard: '⇁',
15566
+ rightharpoondown: '⇁',
15567
+ rharu: '⇀',
15568
+ rightharpoonup: '⇀',
15569
+ lsh: '↰',
15570
+ Lsh: '↰',
15571
+ rsh: '↱',
15572
+ Rsh: '↱',
15573
+ ldsh: '↲',
15574
+ rdsh: '↳',
15575
+ hookleftarrow: '↩',
15576
+ hookrightarrow: '↪',
15577
+ mapstoleft: '↤',
15578
+ mapstoup: '↥',
15579
+ map: '↦',
15580
+ mapsto: '↦',
15581
+ mapstodown: '↧',
15582
+ crarr: '↵',
15583
+ nwarrow: '↖',
15584
+ nearrow: '↗',
15585
+ searrow: '↘',
15586
+ swarrow: '↙',
15587
+ nleftarrow: '↚',
15588
+ nleftrightarrow: '↮',
15589
+ nrightarrow: '↛',
15590
+ nrarr: '↛',
15591
+ larrtl: '↢',
15592
+ rarrtl: '↣',
15593
+ leftarrowtail: '↢',
15594
+ rightarrowtail: '↣',
15595
+ twoheadleftarrow: '↞',
15596
+ twoheadrightarrow: '↠',
15597
+ Larr: '↞',
15598
+ Rarr: '↠',
15599
+ larrhk: '↩',
15600
+ rarrhk: '↪',
15601
+ larrlp: '↫',
15602
+ looparrowleft: '↫',
15603
+ rarrlp: '↬',
15604
+ looparrowright: '↬',
15605
+ harrw: '↭',
15606
+ leftrightsquigarrow: '↭',
15607
+ nrarrw: '↝̸',
15608
+ rarrw: '↝',
15609
+ rightsquigarrow: '↝',
15610
+ larrbfs: '⤟',
15611
+ rarrbfs: '⤠',
15612
+ nvHarr: '⤄',
15613
+ nvlArr: '⤂',
15614
+ nvrArr: '⤃',
15615
+ larrfs: '⤝',
15616
+ rarrfs: '⤞',
15617
+ Map: '⤅',
15618
+ larrsim: '⥳',
15619
+ rarrsim: '⥴',
15620
+ harrcir: '⥈',
15621
+ Uarrocir: '⥉',
15622
+ lurdshar: '⥊',
15623
+ ldrdhar: '⥧',
15624
+ ldrushar: '⥋',
15625
+ rdldhar: '⥩',
15626
+ lrhard: '⥭',
15627
+ rlhar: '⇌',
15628
+ uharr: '↾',
15629
+ uharl: '↿',
15630
+ dharr: '⇂',
15631
+ dharl: '⇃',
15632
+ Uarr: '↟',
15633
+ Darr: '↡',
15634
+ zigrarr: '⇝',
15635
+ nwArr: '⇖',
15636
+ neArr: '⇗',
15637
+ seArr: '⇘',
15638
+ swArr: '⇙',
15639
+ nharr: '↮',
15640
+ nhArr: '⇎',
15641
+ nlarr: '↚',
15642
+ nlArr: '⇍',
15643
+ nrarr: '↛',
15644
+ nrArr: '⇏',
15645
+ larrb: '⇤',
15646
+ LeftArrowBar: '⇤',
15647
+ rarrb: '⇥',
15648
+ RightArrowBar: '⇥'
15649
+ };
15650
+ const SHAPES = {
15651
+ square: '□',
15652
+ Square: '□',
15653
+ squ: '□',
15654
+ squf: '▪',
15655
+ squarf: '▪',
15656
+ blacksquar: '▪',
15657
+ blacksquare: '▪',
15658
+ FilledVerySmallSquare: '▪',
15659
+ blk34: '▓',
15660
+ blk12: '▒',
15661
+ blk14: '░',
15662
+ block: '█',
15663
+ srect: '▭',
15664
+ rect: '▭',
15665
+ sdot: '⋅',
15666
+ sdotb: '⊡',
15667
+ dotsquare: '⊡',
15668
+ triangle: '▵',
15669
+ tri: '▵',
15670
+ trine: '▵',
15671
+ utri: '▵',
15672
+ triangledown: '▿',
15673
+ dtri: '▿',
15674
+ tridown: '▿',
15675
+ triangleleft: '◃',
15676
+ ltri: '◃',
15677
+ triangleright: '▹',
15678
+ rtri: '▹',
15679
+ blacktriangle: '▴',
15680
+ utrif: '▴',
15681
+ blacktriangledown: '▾',
15682
+ dtrif: '▾',
15683
+ blacktriangleleft: '◂',
15684
+ ltrif: '◂',
15685
+ blacktriangleright: '▸',
15686
+ rtrif: '▸',
15687
+ loz: '◊',
15688
+ lozenge: '◊',
15689
+ blacklozenge: '⧫',
15690
+ lozf: '⧫',
15691
+ bigcirc: '◯',
15692
+ xcirc: '◯',
15693
+ circ: 'ˆ',
15694
+ Circle: '○',
15695
+ cir: '○',
15696
+ o: '○',
15697
+ bullet: '•',
15698
+ bull: '•',
15699
+ hellip: '…',
15700
+ mldr: '…',
15701
+ nldr: '‥',
15702
+ boxh: '─',
15703
+ HorizontalLine: '─',
15704
+ boxv: '│',
15705
+ boxdr: '┌',
15706
+ boxdl: '┐',
15707
+ boxur: '└',
15708
+ boxul: '┘',
15709
+ boxvr: '├',
15710
+ boxvl: '┤',
15711
+ boxhd: '┬',
15712
+ boxhu: '┴',
15713
+ boxvh: '┼',
15714
+ boxH: '═',
15715
+ boxV: '║',
15716
+ boxdR: '╒',
15717
+ boxDr: '╓',
15718
+ boxDR: '╔',
15719
+ boxDl: '╕',
15720
+ boxdL: '╖',
15721
+ boxDL: '╗',
15722
+ boxuR: '╘',
15723
+ boxUr: '╙',
15724
+ boxUR: '╚',
15725
+ boxUl: '╜',
15726
+ boxuL: '╛',
15727
+ boxUL: '╝',
15728
+ boxvR: '╞',
15729
+ boxVr: '╟',
15730
+ boxVR: '╠',
15731
+ boxVl: '╢',
15732
+ boxvL: '╡',
15733
+ boxVL: '╣',
15734
+ boxHd: '╤',
15735
+ boxhD: '╥',
15736
+ boxHD: '╦',
15737
+ boxHu: '╧',
15738
+ boxhU: '╨',
15739
+ boxHU: '╩',
15740
+ boxvH: '╪',
15741
+ boxVh: '╫',
15742
+ boxVH: '╬'
15743
+ };
15744
+ const PUNCTUATION = {
15745
+ excl: '!',
15746
+ iexcl: '¡',
15747
+ brvbar: '¦',
15748
+ sect: '§',
15749
+ uml: '¨',
15750
+ copy: '©',
15751
+ ordf: 'ª',
15752
+ laquo: '«',
15753
+ not: '¬',
15754
+ shy: '\u00ad',
15755
+ reg: '®',
15756
+ macr: '¯',
15757
+ deg: '°',
15758
+ plusmn: '±',
15759
+ sup2: '²',
15760
+ sup3: '³',
15761
+ acute: '´',
15762
+ micro: 'µ',
15763
+ para: '¶',
15764
+ middot: '·',
15765
+ cedil: '¸',
15766
+ sup1: '¹',
15767
+ ordm: 'º',
15768
+ raquo: '»',
15769
+ frac14: '¼',
15770
+ frac12: '½',
15771
+ frac34: '¾',
15772
+ iquest: '¿',
15773
+ nbsp: '\u00a0',
15774
+ comma: ',',
15775
+ period: '.',
15776
+ colon: ':',
15777
+ semi: ';',
15778
+ vert: '|',
15779
+ Verbar: '‖',
15780
+ verbar: '|',
15781
+ dblac: '˝',
15782
+ circ: 'ˆ',
15783
+ caron: 'ˇ',
15784
+ breve: '˘',
15785
+ dot: '˙',
15786
+ ring: '˚',
15787
+ ogon: '˛',
15788
+ tilde: '˜',
15789
+ DiacriticalGrave: '`',
15790
+ DiacriticalAcute: '´',
15791
+ DiacriticalTilde: '˜',
15792
+ DiacriticalDot: '˙',
15793
+ DiacriticalDoubleAcute: '˝',
15794
+ grave: '`',
15795
+ acute: '´'
15796
+ };
15797
+ const CURRENCY = {
15798
+ cent: '¢',
15799
+ pound: '£',
15800
+ curren: '¤',
15801
+ yen: '¥',
15802
+ euro: '€',
15803
+ dollar: '$',
15804
+ euro: '€',
15805
+ fnof: 'ƒ',
15806
+ inr: '₹',
15807
+ af: '؋',
15808
+ birr: 'ብር',
15809
+ peso: '₱',
15810
+ rub: '₽',
15811
+ won: '₩',
15812
+ yuan: '¥',
15813
+ cedil: '¸'
15814
+ };
15815
+ const FRACTIONS = {
15816
+ frac12: '½',
15817
+ half: '½',
15818
+ frac13: '⅓',
15819
+ frac14: '¼',
15820
+ frac15: '⅕',
15821
+ frac16: '⅙',
15822
+ frac18: '⅛',
15823
+ frac23: '⅔',
15824
+ frac25: '⅖',
15825
+ frac34: '¾',
15826
+ frac35: '⅗',
15827
+ frac38: '⅜',
15828
+ frac45: '⅘',
15829
+ frac56: '⅚',
15830
+ frac58: '⅝',
15831
+ frac78: '⅞',
15832
+ frasl: '⁄'
15833
+ };
15834
+ const MISC_SYMBOLS = {
15835
+ trade: '™',
15836
+ TRADE: '™',
15837
+ telrec: '⌕',
15838
+ target: '⌖',
15839
+ ulcorn: '⌜',
15840
+ ulcorner: '⌜',
15841
+ urcorn: '⌝',
15842
+ urcorner: '⌝',
15843
+ dlcorn: '⌞',
15844
+ llcorner: '⌞',
15845
+ drcorn: '⌟',
15846
+ lrcorner: '⌟',
15847
+ intercal: '⊺',
15848
+ intcal: '⊺',
15849
+ oplus: '⊕',
15850
+ CirclePlus: '⊕',
15851
+ ominus: '⊖',
15852
+ CircleMinus: '⊖',
15853
+ otimes: '⊗',
15854
+ CircleTimes: '⊗',
15855
+ osol: '⊘',
15856
+ odot: '⊙',
15857
+ CircleDot: '⊙',
15858
+ oast: '⊛',
15859
+ circledast: '⊛',
15860
+ odash: '⊝',
15861
+ circleddash: '⊝',
15862
+ ocirc: '⊚',
15863
+ circledcirc: '⊚',
15864
+ boxplus: '⊞',
15865
+ plusb: '⊞',
15866
+ boxminus: '⊟',
15867
+ minusb: '⊟',
15868
+ boxtimes: '⊠',
15869
+ timesb: '⊠',
15870
+ boxdot: '⊡',
15871
+ sdotb: '⊡',
15872
+ veebar: '⊻',
15873
+ vee: '∨',
15874
+ barvee: '⊽',
15875
+ and: '∧',
15876
+ wedge: '∧',
15877
+ Cap: '⋒',
15878
+ Cup: '⋓',
15879
+ Fork: '⋔',
15880
+ pitchfork: '⋔',
15881
+ epar: '⋕',
15882
+ ltlarr: '⥶',
15883
+ nvap: '≍⃒',
15884
+ nvsim: '∼⃒',
15885
+ nvge: '≥⃒',
15886
+ nvle: '≤⃒',
15887
+ nvlt: '<⃒',
15888
+ nvgt: '>⃒',
15889
+ nvltrie: '⊴⃒',
15890
+ nvrtrie: '⊵⃒',
15891
+ Vdash: '⊩',
15892
+ dashv: '⊣',
15893
+ vDash: '⊨',
15894
+ Vdash: '⊩',
15895
+ Vvdash: '⊪',
15896
+ nvdash: '⊬',
15897
+ nvDash: '⊭',
15898
+ nVdash: '⊮',
15899
+ nVDash: '⊯'
15900
+ };
15901
+ ({
15902
+ ...BASIC_LATIN,
15903
+ ...LATIN_ACCENTS,
15904
+ ...LATIN_EXTENDED,
15905
+ ...GREEK,
15906
+ ...CYRILLIC,
15907
+ ...MATH,
15908
+ ...MATH_ADVANCED,
15909
+ ...ARROWS,
15910
+ ...SHAPES,
15911
+ ...PUNCTUATION,
15912
+ ...CURRENCY,
15913
+ ...FRACTIONS,
15914
+ ...MISC_SYMBOLS
15915
+ });
15916
+ const XML = {
15917
+ amp: "&",
15918
+ apos: "'",
15919
+ gt: ">",
15920
+ lt: "<",
15921
+ quot: "\""
15922
+ };
15923
+ const COMMON_HTML = {
15924
+ nbsp: '\u00a0',
15925
+ copy: '\u00a9',
15926
+ reg: '\u00ae',
15927
+ trade: '\u2122',
15928
+ mdash: '\u2014',
15929
+ ndash: '\u2013',
15930
+ hellip: '\u2026',
15931
+ laquo: '\u00ab',
15932
+ raquo: '\u00bb',
15933
+ lsquo: '\u2018',
15934
+ rsquo: '\u2019',
15935
+ ldquo: '\u201c',
15936
+ rdquo: '\u201d',
15937
+ bull: '\u2022',
15938
+ para: '\u00b6',
15939
+ sect: '\u00a7',
15940
+ deg: '\u00b0',
15941
+ frac12: '\u00bd',
15942
+ frac14: '\u00bc',
15943
+ frac34: '\u00be'
15944
+ };
15945
+ const SPECIAL_CHARS = new Set('!?\\\\/[]$%{}^&*()<>|+');
15946
+ function EntityDecoder_validateEntityName(name) {
15947
+ if ('#' === name[0]) throw new Error(`[EntityReplacer] Invalid character '#' in entity name: "${name}"`);
15948
+ for (const ch of name)if (SPECIAL_CHARS.has(ch)) throw new Error(`[EntityReplacer] Invalid character '${ch}' in entity name: "${name}"`);
15949
+ return name;
15950
+ }
15951
+ function mergeEntityMaps(...maps) {
15952
+ const out = Object.create(null);
15953
+ for (const map of maps)if (map) for (const key of Object.keys(map)){
15954
+ const raw = map[key];
15955
+ if ('string' == typeof raw) out[key] = raw;
15956
+ else if (raw && 'object' == typeof raw && void 0 !== raw.val) {
15957
+ const val = raw.val;
15958
+ if ('string' == typeof val) out[key] = val;
15959
+ }
15960
+ }
15961
+ return out;
15962
+ }
15963
+ const LIMIT_TIER_EXTERNAL = 'external';
15964
+ const LIMIT_TIER_BASE = 'base';
15965
+ const LIMIT_TIER_ALL = 'all';
15966
+ function parseLimitTiers(raw) {
15967
+ if (!raw || raw === LIMIT_TIER_EXTERNAL) return new Set([
15968
+ LIMIT_TIER_EXTERNAL
15969
+ ]);
15970
+ if (raw === LIMIT_TIER_ALL) return new Set([
15971
+ LIMIT_TIER_ALL
15972
+ ]);
15973
+ if (raw === LIMIT_TIER_BASE) return new Set([
15974
+ LIMIT_TIER_BASE
15975
+ ]);
15976
+ if (Array.isArray(raw)) return new Set(raw);
15977
+ return new Set([
15978
+ LIMIT_TIER_EXTERNAL
15979
+ ]);
15980
+ }
15981
+ const NCR_LEVEL = Object.freeze({
15982
+ allow: 0,
15983
+ leave: 1,
15984
+ remove: 2,
15985
+ throw: 3
15986
+ });
15987
+ const XML10_ALLOWED_C0 = new Set([
15988
+ 0x09,
15989
+ 0x0A,
15990
+ 0x0D
15991
+ ]);
15992
+ function parseNCRConfig(ncr) {
15993
+ if (!ncr) return {
15994
+ xmlVersion: 1.0,
15995
+ onLevel: NCR_LEVEL.allow,
15996
+ nullLevel: NCR_LEVEL.remove
15997
+ };
15998
+ const xmlVersion = 1.1 === ncr.xmlVersion ? 1.1 : 1.0;
15999
+ const onLevel = NCR_LEVEL[ncr.onNCR] ?? NCR_LEVEL.allow;
16000
+ const nullLevel = NCR_LEVEL[ncr.nullNCR] ?? NCR_LEVEL.remove;
16001
+ const clampedNull = Math.max(nullLevel, NCR_LEVEL.remove);
16002
+ return {
16003
+ xmlVersion,
16004
+ onLevel,
16005
+ nullLevel: clampedNull
16006
+ };
16007
+ }
16008
+ class EntityDecoder {
16009
+ constructor(options = {}){
16010
+ this._limit = options.limit || {};
16011
+ this._maxTotalExpansions = this._limit.maxTotalExpansions || 0;
16012
+ this._maxExpandedLength = this._limit.maxExpandedLength || 0;
16013
+ this._postCheck = 'function' == typeof options.postCheck ? options.postCheck : (r)=>r;
16014
+ this._limitTiers = parseLimitTiers(this._limit.applyLimitsTo ?? LIMIT_TIER_EXTERNAL);
16015
+ this._numericAllowed = options.numericAllowed ?? true;
16016
+ this._baseMap = mergeEntityMaps(XML, options.namedEntities || null);
16017
+ this._externalMap = Object.create(null);
16018
+ this._inputMap = Object.create(null);
16019
+ this._totalExpansions = 0;
16020
+ this._expandedLength = 0;
16021
+ this._removeSet = new Set(options.remove && Array.isArray(options.remove) ? options.remove : []);
16022
+ this._leaveSet = new Set(options.leave && Array.isArray(options.leave) ? options.leave : []);
16023
+ const ncrCfg = parseNCRConfig(options.ncr);
16024
+ this._ncrXmlVersion = ncrCfg.xmlVersion;
16025
+ this._ncrOnLevel = ncrCfg.onLevel;
16026
+ this._ncrNullLevel = ncrCfg.nullLevel;
16027
+ }
16028
+ setExternalEntities(map) {
16029
+ if (map) for (const key of Object.keys(map))EntityDecoder_validateEntityName(key);
16030
+ this._externalMap = mergeEntityMaps(map);
16031
+ }
16032
+ addExternalEntity(key, value) {
16033
+ EntityDecoder_validateEntityName(key);
16034
+ if ('string' == typeof value && -1 === value.indexOf('&')) this._externalMap[key] = value;
16035
+ }
16036
+ addInputEntities(map) {
16037
+ this._totalExpansions = 0;
16038
+ this._expandedLength = 0;
16039
+ this._inputMap = mergeEntityMaps(map);
16040
+ }
16041
+ reset() {
16042
+ this._inputMap = Object.create(null);
16043
+ this._totalExpansions = 0;
16044
+ this._expandedLength = 0;
16045
+ return this;
16046
+ }
16047
+ setXmlVersion(version) {
16048
+ this._ncrXmlVersion = 1.1 === version ? 1.1 : 1.0;
16049
+ }
16050
+ decode(str) {
16051
+ if ('string' != typeof str || 0 === str.length) return str;
16052
+ const original = str;
16053
+ const chunks = [];
16054
+ const len = str.length;
16055
+ let last = 0;
16056
+ let i = 0;
16057
+ const limitExpansions = this._maxTotalExpansions > 0;
16058
+ const limitLength = this._maxExpandedLength > 0;
16059
+ const checkLimits = limitExpansions || limitLength;
16060
+ while(i < len){
16061
+ if (38 !== str.charCodeAt(i)) {
16062
+ i++;
16063
+ continue;
16064
+ }
16065
+ let j = i + 1;
16066
+ while(j < len && 59 !== str.charCodeAt(j) && j - i <= 32)j++;
16067
+ if (j >= len || 59 !== str.charCodeAt(j)) {
16068
+ i++;
16069
+ continue;
16070
+ }
16071
+ const token = str.slice(i + 1, j);
16072
+ if (0 === token.length) {
16073
+ i++;
16074
+ continue;
16075
+ }
16076
+ let replacement;
16077
+ let tier;
16078
+ if (this._removeSet.has(token)) {
16079
+ replacement = '';
16080
+ if (void 0 === tier) tier = LIMIT_TIER_EXTERNAL;
16081
+ } else if (this._leaveSet.has(token)) {
16082
+ i++;
16083
+ continue;
16084
+ } else if (35 === token.charCodeAt(0)) {
16085
+ const ncrResult = this._resolveNCR(token);
16086
+ if (void 0 === ncrResult) {
16087
+ i++;
16088
+ continue;
16089
+ }
16090
+ replacement = ncrResult;
16091
+ tier = LIMIT_TIER_BASE;
16092
+ } else {
16093
+ const resolved = this._resolveName(token);
16094
+ replacement = resolved?.value;
16095
+ tier = resolved?.tier;
16096
+ }
16097
+ if (void 0 === replacement) {
16098
+ i++;
16099
+ continue;
16100
+ }
16101
+ if (i > last) chunks.push(str.slice(last, i));
16102
+ chunks.push(replacement);
16103
+ last = j + 1;
16104
+ i = last;
16105
+ if (checkLimits && this._tierCounts(tier)) {
16106
+ if (limitExpansions) {
16107
+ this._totalExpansions++;
16108
+ if (this._totalExpansions > this._maxTotalExpansions) throw new Error(`[EntityReplacer] Entity expansion count limit exceeded: ${this._totalExpansions} > ${this._maxTotalExpansions}`);
16109
+ }
16110
+ if (limitLength) {
16111
+ const delta = replacement.length - (token.length + 2);
16112
+ if (delta > 0) {
16113
+ this._expandedLength += delta;
16114
+ if (this._expandedLength > this._maxExpandedLength) throw new Error(`[EntityReplacer] Expanded content length limit exceeded: ${this._expandedLength} > ${this._maxExpandedLength}`);
16115
+ }
16116
+ }
16117
+ }
16118
+ }
16119
+ if (last < len) chunks.push(str.slice(last));
16120
+ const result = 0 === chunks.length ? str : chunks.join('');
16121
+ return this._postCheck(result, original);
16122
+ }
16123
+ _tierCounts(tier) {
16124
+ if (this._limitTiers.has(LIMIT_TIER_ALL)) return true;
16125
+ return this._limitTiers.has(tier);
16126
+ }
16127
+ _resolveName(name) {
16128
+ if (name in this._inputMap) return {
16129
+ value: this._inputMap[name],
16130
+ tier: LIMIT_TIER_EXTERNAL
16131
+ };
16132
+ if (name in this._externalMap) return {
16133
+ value: this._externalMap[name],
16134
+ tier: LIMIT_TIER_EXTERNAL
16135
+ };
16136
+ if (name in this._baseMap) return {
16137
+ value: this._baseMap[name],
16138
+ tier: LIMIT_TIER_BASE
16139
+ };
16140
+ }
16141
+ _classifyNCR(cp) {
16142
+ if (0 === cp) return this._ncrNullLevel;
16143
+ if (cp >= 0xD800 && cp <= 0xDFFF) return NCR_LEVEL.remove;
16144
+ if (1.0 === this._ncrXmlVersion) {
16145
+ if (cp >= 0x01 && cp <= 0x1F && !XML10_ALLOWED_C0.has(cp)) return NCR_LEVEL.remove;
16146
+ }
16147
+ return -1;
16148
+ }
16149
+ _applyNCRAction(action, token, cp) {
16150
+ switch(action){
16151
+ case NCR_LEVEL.allow:
16152
+ return String.fromCodePoint(cp);
16153
+ case NCR_LEVEL.remove:
16154
+ return '';
16155
+ case NCR_LEVEL.leave:
16156
+ return;
16157
+ case NCR_LEVEL.throw:
16158
+ throw new Error(`[EntityDecoder] Prohibited numeric character reference &${token}; (U+${cp.toString(16).toUpperCase().padStart(4, '0')})`);
16159
+ default:
16160
+ return String.fromCodePoint(cp);
16161
+ }
16162
+ }
16163
+ _resolveNCR(token) {
16164
+ const second = token.charCodeAt(1);
16165
+ let cp;
16166
+ cp = 120 === second || 88 === second ? parseInt(token.slice(2), 16) : parseInt(token.slice(1), 10);
16167
+ if (Number.isNaN(cp) || cp < 0 || cp > 0x10FFFF) return;
16168
+ const minimum = this._classifyNCR(cp);
16169
+ if (!this._numericAllowed && minimum < NCR_LEVEL.remove) return;
16170
+ const effective = -1 === minimum ? this._ncrOnLevel : Math.max(this._ncrOnLevel, minimum);
16171
+ return this._applyNCRAction(effective, token, cp);
16172
+ }
16173
+ }
14848
16174
  function extractRawAttributes(prefixedAttrs, options) {
14849
16175
  if (!prefixedAttrs) return {};
14850
16176
  const attrs = options.attributesGroupName ? prefixedAttrs[options.attributesGroupName] : prefixedAttrs;
@@ -14865,76 +16191,10 @@
14865
16191
  }
14866
16192
  }
14867
16193
  class OrderedObjParser {
14868
- constructor(options){
16194
+ constructor(options, externalEntities){
14869
16195
  this.options = options;
14870
16196
  this.currentNode = null;
14871
16197
  this.tagsNodeStack = [];
14872
- this.docTypeEntities = {};
14873
- this.lastEntities = {
14874
- apos: {
14875
- regex: /&(apos|#39|#x27);/g,
14876
- val: "'"
14877
- },
14878
- gt: {
14879
- regex: /&(gt|#62|#x3E);/g,
14880
- val: ">"
14881
- },
14882
- lt: {
14883
- regex: /&(lt|#60|#x3C);/g,
14884
- val: "<"
14885
- },
14886
- quot: {
14887
- regex: /&(quot|#34|#x22);/g,
14888
- val: "\""
14889
- }
14890
- };
14891
- this.ampEntity = {
14892
- regex: /&(amp|#38|#x26);/g,
14893
- val: "&"
14894
- };
14895
- this.htmlEntities = {
14896
- space: {
14897
- regex: /&(nbsp|#160);/g,
14898
- val: " "
14899
- },
14900
- cent: {
14901
- regex: /&(cent|#162);/g,
14902
- val: "¢"
14903
- },
14904
- pound: {
14905
- regex: /&(pound|#163);/g,
14906
- val: "£"
14907
- },
14908
- yen: {
14909
- regex: /&(yen|#165);/g,
14910
- val: "¥"
14911
- },
14912
- euro: {
14913
- regex: /&(euro|#8364);/g,
14914
- val: "€"
14915
- },
14916
- copyright: {
14917
- regex: /&(copy|#169);/g,
14918
- val: "©"
14919
- },
14920
- reg: {
14921
- regex: /&(reg|#174);/g,
14922
- val: "®"
14923
- },
14924
- inr: {
14925
- regex: /&(inr|#8377);/g,
14926
- val: "₹"
14927
- },
14928
- num_dec: {
14929
- regex: /&#([0-9]{1,7});/g,
14930
- val: (_, str)=>fromCodePoint(str, 10, "&#")
14931
- },
14932
- num_hex: {
14933
- regex: /&#x([0-9a-fA-F]{1,6});/g,
14934
- val: (_, str)=>fromCodePoint(str, 16, "&#x")
14935
- }
14936
- };
14937
- this.addExternalEntities = addExternalEntities;
14938
16198
  this.parseXml = parseXml;
14939
16199
  this.parseTextData = parseTextData;
14940
16200
  this.resolveNameSpace = resolveNameSpace;
@@ -14947,6 +16207,29 @@
14947
16207
  this.ignoreAttributesFn = getIgnoreAttributesFn(this.options.ignoreAttributes);
14948
16208
  this.entityExpansionCount = 0;
14949
16209
  this.currentExpandedLength = 0;
16210
+ let namedEntities = {
16211
+ ...XML
16212
+ };
16213
+ if (this.options.entityDecoder) this.entityDecoder = this.options.entityDecoder;
16214
+ else {
16215
+ if ("object" == typeof this.options.htmlEntities) namedEntities = this.options.htmlEntities;
16216
+ else if (true === this.options.htmlEntities) namedEntities = {
16217
+ ...COMMON_HTML,
16218
+ ...CURRENCY
16219
+ };
16220
+ this.entityDecoder = new EntityDecoder({
16221
+ namedEntities: {
16222
+ ...namedEntities,
16223
+ ...externalEntities
16224
+ },
16225
+ numericAllowed: this.options.htmlEntities,
16226
+ limit: {
16227
+ maxTotalExpansions: this.options.processEntities.maxTotalExpansions,
16228
+ maxExpandedLength: this.options.processEntities.maxExpandedLength,
16229
+ applyLimitsTo: this.options.processEntities.appliesTo
16230
+ }
16231
+ });
16232
+ }
14950
16233
  this.matcher = new Matcher();
14951
16234
  this.readonlyMatcher = this.matcher.readOnly();
14952
16235
  this.isCurrentNodeStopNode = false;
@@ -14962,17 +16245,6 @@
14962
16245
  }
14963
16246
  }
14964
16247
  }
14965
- function addExternalEntities(externalEntities) {
14966
- const entKeys = Object.keys(externalEntities);
14967
- for(let i = 0; i < entKeys.length; i++){
14968
- const ent = entKeys[i];
14969
- const escaped = ent.replace(/[.\-+*:]/g, '\\.');
14970
- this.lastEntities[ent] = {
14971
- regex: new RegExp("&" + escaped + ";", "g"),
14972
- val: externalEntities[ent]
14973
- };
14974
- }
14975
- }
14976
16248
  function parseTextData(val, tagName, jPath, dontTrim, hasAttributes, isLeafNode, escapeEntities) {
14977
16249
  const options = this.options;
14978
16250
  if (void 0 !== val) {
@@ -15002,9 +16274,9 @@
15002
16274
  return tagname;
15003
16275
  }
15004
16276
  const attrsRegx = new RegExp('([^\\s=]+)\\s*(=\\s*([\'"])([\\s\\S]*?)\\3)?', 'gm');
15005
- function buildAttributesMap(attrStr, jPath, tagName) {
16277
+ function buildAttributesMap(attrStr, jPath, tagName, force = false) {
15006
16278
  const options = this.options;
15007
- if (true !== options.ignoreAttributes && 'string' == typeof attrStr) {
16279
+ if (true === force || true !== options.ignoreAttributes && 'string' == typeof attrStr) {
15008
16280
  const matches = getAllMatches(attrStr, attrsRegx);
15009
16281
  const len = matches.length;
15010
16282
  const attrs = {};
@@ -15047,7 +16319,7 @@
15047
16319
  }
15048
16320
  }
15049
16321
  if (!hasAttrs) return;
15050
- if (options.attributesGroupName) {
16322
+ if (options.attributesGroupName && !options.preserveOrder) {
15051
16323
  const attrCollection = {};
15052
16324
  attrCollection[options.attributesGroupName] = attrs;
15053
16325
  return attrCollection;
@@ -15061,11 +16333,9 @@
15061
16333
  let currentNode = xmlObj;
15062
16334
  let textData = "";
15063
16335
  this.matcher.reset();
16336
+ this.entityDecoder.reset();
15064
16337
  this.entityExpansionCount = 0;
15065
16338
  this.currentExpandedLength = 0;
15066
- this.docTypeEntitiesKeys = [];
15067
- this.lastEntitiesKeys = Object.keys(this.lastEntities);
15068
- this.htmlEntitiesKeys = this.options.htmlEntities ? Object.keys(this.htmlEntities) : [];
15069
16339
  const options = this.options;
15070
16340
  const docTypeReader = new DocTypeReader(options.processEntities);
15071
16341
  const xmlLen = xmlData.length;
@@ -15097,11 +16367,16 @@
15097
16367
  let tagData = readTagExp(xmlData, i, false, "?>");
15098
16368
  if (!tagData) throw new Error("Pi Tag is not closed.");
15099
16369
  textData = this.saveTextToParentTag(textData, currentNode, this.readonlyMatcher);
16370
+ const attsMap = this.buildAttributesMap(tagData.tagExp, this.matcher, tagData.tagName, true);
16371
+ if (attsMap) {
16372
+ const ver = attsMap[this.options.attributeNamePrefix + "version"];
16373
+ this.entityDecoder.setXmlVersion(Number(ver) || 1.0);
16374
+ }
15100
16375
  if (options.ignoreDeclaration && "?xml" === tagData.tagName || options.ignorePiTags) ;
15101
16376
  else {
15102
16377
  const childNode = new XmlNode(tagData.tagName);
15103
16378
  childNode.add(options.textNodeName, "");
15104
- if (tagData.tagName !== tagData.tagExp && tagData.attrExpPresent) childNode[":@"] = this.buildAttributesMap(tagData.tagExp, this.matcher, tagData.tagName);
16379
+ if (tagData.tagName !== tagData.tagExp && tagData.attrExpPresent && true !== options.ignoreAttributes) childNode[":@"] = attsMap;
15105
16380
  this.addChild(currentNode, childNode, this.readonlyMatcher, i);
15106
16381
  }
15107
16382
  i = tagData.closeIndex + 1;
@@ -15119,8 +16394,7 @@
15119
16394
  i = endIndex;
15120
16395
  } else if (33 === c1 && 68 === xmlData.charCodeAt(i + 2)) {
15121
16396
  const result = docTypeReader.readDocType(xmlData, i);
15122
- this.docTypeEntities = result.entities;
15123
- this.docTypeEntitiesKeys = Object.keys(this.docTypeEntities) || [];
16397
+ this.entityDecoder.addInputEntities(result.entities);
15124
16398
  i = result.i;
15125
16399
  } else if (33 === c1 && 91 === xmlData.charCodeAt(i + 2)) {
15126
16400
  const closeIndex = findClosingIndex(xmlData, "]]>", i, "CDATA is not closed.") - 2;
@@ -15245,42 +16519,7 @@
15245
16519
  const jPathOrMatcher = this.options.jPath ? jPath.toString() : jPath;
15246
16520
  if (!entityConfig.tagFilter(tagName, jPathOrMatcher)) return val;
15247
16521
  }
15248
- for (const entityName of this.docTypeEntitiesKeys){
15249
- const entity = this.docTypeEntities[entityName];
15250
- const matches = val.match(entity.regx);
15251
- if (matches) {
15252
- this.entityExpansionCount += matches.length;
15253
- if (entityConfig.maxTotalExpansions && this.entityExpansionCount > entityConfig.maxTotalExpansions) throw new Error(`Entity expansion limit exceeded: ${this.entityExpansionCount} > ${entityConfig.maxTotalExpansions}`);
15254
- const lengthBefore = val.length;
15255
- val = val.replace(entity.regx, entity.val);
15256
- if (entityConfig.maxExpandedLength) {
15257
- this.currentExpandedLength += val.length - lengthBefore;
15258
- if (this.currentExpandedLength > entityConfig.maxExpandedLength) throw new Error(`Total expanded content size exceeded: ${this.currentExpandedLength} > ${entityConfig.maxExpandedLength}`);
15259
- }
15260
- }
15261
- }
15262
- if (-1 === val.indexOf('&')) return val;
15263
- for (const entityName of this.lastEntitiesKeys){
15264
- const entity = this.lastEntities[entityName];
15265
- const matches = val.match(entity.regex);
15266
- if (matches) {
15267
- this.entityExpansionCount += matches.length;
15268
- if (entityConfig.maxTotalExpansions && this.entityExpansionCount > entityConfig.maxTotalExpansions) throw new Error(`Entity expansion limit exceeded: ${this.entityExpansionCount} > ${entityConfig.maxTotalExpansions}`);
15269
- }
15270
- val = val.replace(entity.regex, entity.val);
15271
- }
15272
- if (-1 === val.indexOf('&')) return val;
15273
- for (const entityName of this.htmlEntitiesKeys){
15274
- const entity = this.htmlEntities[entityName];
15275
- const matches = val.match(entity.regex);
15276
- if (matches) {
15277
- this.entityExpansionCount += matches.length;
15278
- if (entityConfig.maxTotalExpansions && this.entityExpansionCount > entityConfig.maxTotalExpansions) throw new Error(`Entity expansion limit exceeded: ${this.entityExpansionCount} > ${entityConfig.maxTotalExpansions}`);
15279
- }
15280
- val = val.replace(entity.regex, entity.val);
15281
- }
15282
- val = val.replace(this.ampEntity.regex, this.ampEntity.val);
15283
- return val;
16522
+ return this.entityDecoder.decode(val);
15284
16523
  }
15285
16524
  function saveTextToParentTag(textData, parentNode, matcher, isLeafNode) {
15286
16525
  if (textData) {
@@ -15297,29 +16536,35 @@
15297
16536
  }
15298
16537
  function tagExpWithClosingIndex(xmlData, i, closingChar = ">") {
15299
16538
  let attrBoundary = 0;
15300
- const chars = [];
15301
16539
  const len = xmlData.length;
15302
16540
  const closeCode0 = closingChar.charCodeAt(0);
15303
16541
  const closeCode1 = closingChar.length > 1 ? closingChar.charCodeAt(1) : -1;
16542
+ let result = '';
16543
+ let segmentStart = i;
15304
16544
  for(let index = i; index < len; index++){
15305
16545
  const code = xmlData.charCodeAt(index);
15306
16546
  if (attrBoundary) {
15307
16547
  if (code === attrBoundary) attrBoundary = 0;
15308
16548
  } else if (34 === code || 39 === code) attrBoundary = code;
15309
- else if (code === closeCode0) {
15310
- if (-1 === closeCode1) return {
15311
- data: String.fromCharCode(...chars),
15312
- index
15313
- };
15314
- else if (xmlData.charCodeAt(index + 1) === closeCode1) return {
15315
- data: String.fromCharCode(...chars),
16549
+ else if (code === closeCode0) if (-1 !== closeCode1) {
16550
+ if (xmlData.charCodeAt(index + 1) === closeCode1) {
16551
+ result += xmlData.substring(segmentStart, index);
16552
+ return {
16553
+ data: result,
16554
+ index
16555
+ };
16556
+ }
16557
+ } else {
16558
+ result += xmlData.substring(segmentStart, index);
16559
+ return {
16560
+ data: result,
15316
16561
  index
15317
16562
  };
15318
- } else if (9 === code) {
15319
- chars.push(32);
15320
- continue;
15321
16563
  }
15322
- chars.push(code);
16564
+ else if (9 === code && !attrBoundary) {
16565
+ result += xmlData.substring(segmentStart, index) + ' ';
16566
+ segmentStart = index + 1;
16567
+ }
15323
16568
  }
15324
16569
  }
15325
16570
  function findClosingIndex(xmlData, str, i, errMsg) {
@@ -15387,7 +16632,7 @@
15387
16632
  const closeIndex = findClosingIndex(xmlData, "]]>", i, "StopNode is not closed.") - 2;
15388
16633
  i = closeIndex;
15389
16634
  } else {
15390
- const tagData = readTagExp(xmlData, i, '>');
16635
+ const tagData = readTagExp(xmlData, i, false);
15391
16636
  if (tagData) {
15392
16637
  const openTagName = tagData && tagData.tagName;
15393
16638
  if (openTagName === tagName && "/" !== tagData.tagExp[tagData.tagExp.length - 1]) openTagCount++;
@@ -15406,11 +16651,6 @@
15406
16651
  if (isExist(val)) return val;
15407
16652
  return '';
15408
16653
  }
15409
- function fromCodePoint(str, base, prefix) {
15410
- const codePoint = Number.parseInt(str, base);
15411
- if (codePoint >= 0 && codePoint <= 0x10FFFF) return String.fromCodePoint(codePoint);
15412
- return prefix + str + ";";
15413
- }
15414
16654
  function transformTagName(fn, tagName, tagExp, options) {
15415
16655
  if (fn) {
15416
16656
  const newTagName = fn(tagName);
@@ -15458,6 +16698,7 @@
15458
16698
  else if (tagObj[property]) {
15459
16699
  let val = node2json_compress(tagObj[property], options, matcher, readonlyMatcher);
15460
16700
  const isLeaf = isLeafTag(val, options);
16701
+ if (0 === Object.keys(val).length && options.alwaysCreateTextNode) val[options.textNodeName] = "";
15461
16702
  if (tagObj[":@"]) assignAttributes(val, tagObj[":@"], readonlyMatcher, options);
15462
16703
  else if (1 !== Object.keys(val).length || void 0 === val[options.textNodeName] || options.alwaysCreateTextNode) {
15463
16704
  if (0 === Object.keys(val).length) if (options.alwaysCreateTextNode) val[options.textNodeName] = "";
@@ -15749,8 +16990,7 @@
15749
16990
  const result = validate(xmlData, validationOption);
15750
16991
  if (true !== result) throw Error(`${result.err.msg}:${result.err.line}:${result.err.col}`);
15751
16992
  }
15752
- const orderedObjParser = new OrderedObjParser(this.options);
15753
- orderedObjParser.addExternalEntities(this.externalEntities);
16993
+ const orderedObjParser = new OrderedObjParser(this.options, this.externalEntities);
15754
16994
  const orderedResult = orderedObjParser.parseXml(xmlData);
15755
16995
  if (this.options.preserveOrder || void 0 === orderedResult) return orderedResult;
15756
16996
  return prettify(orderedResult, this.options, orderedObjParser.matcher, orderedObjParser.readonlyMatcher);
@@ -15765,20 +17005,73 @@
15765
17005
  return XmlNode.getMetaDataSymbol();
15766
17006
  }
15767
17007
  }
17008
+ function safeComment(val) {
17009
+ return String(val).replace(/--/g, '- -').replace(/--/g, '- -').replace(/-$/, '- ');
17010
+ }
17011
+ function safeCdata(val) {
17012
+ return String(val).replace(/\]\]>/g, ']]]]><![CDATA[>');
17013
+ }
17014
+ function escapeAttribute(val) {
17015
+ return String(val).replace(/"/g, '&quot;').replace(/'/g, '&apos;');
17016
+ }
17017
+ const nameStartChar10 = ":A-Za-z_À-ÖØ-öø-˿Ͱ-ͽͿ-҆҈-῿‌-‍⁰-↏Ⰰ-⿯、-퟿豈-﷏ﷰ-�";
17018
+ const nameChar10 = nameStartChar10 + "\\-\\.\\d·̀-ͯ‿-⁀";
17019
+ const nameStartChar11 = ":A-Za-z_À-˿Ͱ-ͽͿ-҆҈-῿‌-‍⁰-↏Ⰰ-⿯、-퟿豈-﷏ﷰ-�𐀀-󯿿";
17020
+ const nameChar11 = nameStartChar11 + "\\-\\.\\d·̀-ͯ҇‿-⁀";
17021
+ const buildRegexes = (startChar, char, flags = '')=>{
17022
+ const ncStart = startChar.replace(':', '');
17023
+ const ncChar = char.replace(':', '');
17024
+ const ncNamePat = `[${ncStart}][${ncChar}]*`;
17025
+ return {
17026
+ name: new RegExp(`^[${startChar}][${char}]*$`, flags),
17027
+ ncName: new RegExp(`^${ncNamePat}$`, flags),
17028
+ qName: new RegExp(`^${ncNamePat}(?::${ncNamePat})?$`, flags),
17029
+ nmToken: new RegExp(`^[${char}]+$`, flags),
17030
+ nmTokens: new RegExp(`^[${char}]+(?:\\s+[${char}]+)*$`, flags)
17031
+ };
17032
+ };
17033
+ const regexes10 = buildRegexes(nameStartChar10, nameChar10);
17034
+ const regexes11 = buildRegexes(nameStartChar11, nameChar11, 'u');
17035
+ const getRegexes = (xmlVersion = '1.0')=>'1.1' === xmlVersion ? regexes11 : regexes10;
17036
+ const qName = (str, { xmlVersion = '1.0' } = {})=>getRegexes(xmlVersion).qName.test(str);
15768
17037
  const EOL = "\n";
17038
+ function detectXmlVersionFromArray(jArray, options) {
17039
+ if (!Array.isArray(jArray) || 0 === jArray.length) return '1.0';
17040
+ const first = jArray[0];
17041
+ const firstKey = orderedJs2Xml_propName(first);
17042
+ if ('?xml' === firstKey) {
17043
+ const attrs = first[':@'];
17044
+ if (attrs) {
17045
+ const versionKey = options.attributeNamePrefix + 'version';
17046
+ if (attrs[versionKey]) return attrs[versionKey];
17047
+ }
17048
+ }
17049
+ return '1.0';
17050
+ }
17051
+ function resolveTagName(name, isAttribute, options, matcher, xmlVersion) {
17052
+ if (!options.sanitizeName) return name;
17053
+ if (qName(name, {
17054
+ xmlVersion
17055
+ })) return name;
17056
+ return options.sanitizeName(name, {
17057
+ isAttribute,
17058
+ matcher: matcher.readOnly()
17059
+ });
17060
+ }
15769
17061
  function toXml(jArray, options) {
15770
17062
  let indentation = "";
15771
- if (options.format && options.indentBy.length > 0) indentation = EOL;
17063
+ if (options.format) indentation = EOL;
15772
17064
  const stopNodeExpressions = [];
15773
17065
  if (options.stopNodes && Array.isArray(options.stopNodes)) for(let i = 0; i < options.stopNodes.length; i++){
15774
17066
  const node = options.stopNodes[i];
15775
17067
  if ('string' == typeof node) stopNodeExpressions.push(new Expression(node));
15776
17068
  else if (node instanceof Expression) stopNodeExpressions.push(node);
15777
17069
  }
17070
+ const xmlVersion = detectXmlVersionFromArray(jArray, options);
15778
17071
  const matcher = new Matcher();
15779
- return arrToStr(jArray, options, indentation, matcher, stopNodeExpressions);
17072
+ return arrToStr(jArray, options, indentation, matcher, stopNodeExpressions, xmlVersion);
15780
17073
  }
15781
- function arrToStr(arr, options, indentation, matcher, stopNodeExpressions) {
17074
+ function arrToStr(arr, options, indentation, matcher, stopNodeExpressions, xmlVersion) {
15782
17075
  let xmlStr = "";
15783
17076
  let isPreviousElementTag = false;
15784
17077
  if (options.maxNestedTags && matcher.getDepth() > options.maxNestedTags) throw new Error("Maximum nested tags exceeded");
@@ -15792,13 +17085,15 @@
15792
17085
  }
15793
17086
  for(let i = 0; i < arr.length; i++){
15794
17087
  const tagObj = arr[i];
15795
- const tagName = orderedJs2Xml_propName(tagObj);
15796
- if (void 0 === tagName) continue;
17088
+ const rawTagName = orderedJs2Xml_propName(tagObj);
17089
+ if (void 0 === rawTagName) continue;
17090
+ const isSpecialName = rawTagName === options.textNodeName || rawTagName === options.cdataPropName || rawTagName === options.commentPropName || '?' === rawTagName[0];
17091
+ const tagName = isSpecialName ? rawTagName : resolveTagName(rawTagName, false, options, matcher, xmlVersion);
15797
17092
  const attrValues = extractAttributeValues(tagObj[":@"], options);
15798
17093
  matcher.push(tagName, attrValues);
15799
17094
  const isStopNode = checkStopNode(matcher, stopNodeExpressions);
15800
17095
  if (tagName === options.textNodeName) {
15801
- let tagText = tagObj[tagName];
17096
+ let tagText = tagObj[rawTagName];
15802
17097
  if (!isStopNode) {
15803
17098
  tagText = options.tagValueProcessor(tagName, tagText);
15804
17099
  tagText = orderedJs2Xml_replaceEntitiesValue(tagText, options);
@@ -15811,32 +17106,34 @@
15811
17106
  }
15812
17107
  if (tagName === options.cdataPropName) {
15813
17108
  if (isPreviousElementTag) xmlStr += indentation;
15814
- xmlStr += `<![CDATA[${tagObj[tagName][0][options.textNodeName]}]]>`;
17109
+ const val = tagObj[rawTagName][0][options.textNodeName];
17110
+ const safeVal = safeCdata(val);
17111
+ xmlStr += `<![CDATA[${safeVal}]]>`;
15815
17112
  isPreviousElementTag = false;
15816
17113
  matcher.pop();
15817
17114
  continue;
15818
17115
  }
15819
17116
  if (tagName === options.commentPropName) {
15820
- xmlStr += indentation + `<!--${tagObj[tagName][0][options.textNodeName]}-->`;
17117
+ const val = tagObj[rawTagName][0][options.textNodeName];
17118
+ const safeVal = safeComment(val);
17119
+ xmlStr += indentation + `<!--${safeVal}-->`;
15821
17120
  isPreviousElementTag = true;
15822
17121
  matcher.pop();
15823
17122
  continue;
15824
17123
  } else if ("?" === tagName[0]) {
15825
- const attStr = attr_to_str(tagObj[":@"], options, isStopNode);
17124
+ const attStr = attr_to_str(tagObj[":@"], options, isStopNode, matcher, xmlVersion);
15826
17125
  const tempInd = "?xml" === tagName ? "" : indentation;
15827
- let piTextNodeName = tagObj[tagName][0][options.textNodeName];
15828
- piTextNodeName = 0 !== piTextNodeName.length ? " " + piTextNodeName : "";
15829
- xmlStr += tempInd + `<${tagName}${piTextNodeName}${attStr}?>`;
17126
+ xmlStr += tempInd + `<${tagName}${attStr}?>`;
15830
17127
  isPreviousElementTag = true;
15831
17128
  matcher.pop();
15832
17129
  continue;
15833
17130
  }
15834
17131
  let newIdentation = indentation;
15835
17132
  if ("" !== newIdentation) newIdentation += options.indentBy;
15836
- const attStr = attr_to_str(tagObj[":@"], options, isStopNode);
17133
+ const attStr = attr_to_str(tagObj[":@"], options, isStopNode, matcher, xmlVersion);
15837
17134
  const tagStart = indentation + `<${tagName}${attStr}`;
15838
17135
  let tagValue;
15839
- tagValue = isStopNode ? getRawContent(tagObj[tagName], options) : arrToStr(tagObj[tagName], options, newIdentation, matcher, stopNodeExpressions);
17136
+ tagValue = isStopNode ? getRawContent(tagObj[rawTagName], options) : arrToStr(tagObj[rawTagName], options, newIdentation, matcher, stopNodeExpressions, xmlVersion);
15840
17137
  if (-1 !== options.unpairedTags.indexOf(tagName)) if (options.suppressUnpairedNode) xmlStr += tagStart + ">";
15841
17138
  else xmlStr += tagStart + "/>";
15842
17139
  else if ((!tagValue || 0 === tagValue.length) && options.suppressEmptyNode) xmlStr += tagStart + "/>";
@@ -15859,7 +17156,7 @@
15859
17156
  for(let attr in attrMap){
15860
17157
  if (!Object.prototype.hasOwnProperty.call(attrMap, attr)) continue;
15861
17158
  const cleanAttrName = attr.startsWith(options.attributeNamePrefix) ? attr.substr(options.attributeNamePrefix.length) : attr;
15862
- attrValues[cleanAttrName] = attrMap[attr];
17159
+ attrValues[cleanAttrName] = escapeAttribute(attrMap[attr]);
15863
17160
  hasAttrs = true;
15864
17161
  }
15865
17162
  return hasAttrs ? attrValues : null;
@@ -15892,7 +17189,7 @@
15892
17189
  if (!Object.prototype.hasOwnProperty.call(attrMap, attr)) continue;
15893
17190
  let attrVal = attrMap[attr];
15894
17191
  if (true === attrVal && options.suppressBooleanAttributes) attrStr += ` ${attr.substr(options.attributeNamePrefix.length)}`;
15895
- else attrStr += ` ${attr.substr(options.attributeNamePrefix.length)}="${attrVal}"`;
17192
+ else attrStr += ` ${attr.substr(options.attributeNamePrefix.length)}="${escapeAttribute(attrVal)}"`;
15896
17193
  }
15897
17194
  return attrStr;
15898
17195
  }
@@ -15905,18 +17202,20 @@
15905
17202
  }
15906
17203
  }
15907
17204
  }
15908
- function attr_to_str(attrMap, options, isStopNode) {
17205
+ function attr_to_str(attrMap, options, isStopNode, matcher, xmlVersion) {
15909
17206
  let attrStr = "";
15910
17207
  if (attrMap && !options.ignoreAttributes) for(let attr in attrMap){
15911
17208
  if (!Object.prototype.hasOwnProperty.call(attrMap, attr)) continue;
17209
+ const cleanAttrName = attr.substr(options.attributeNamePrefix.length);
17210
+ const resolvedAttrName = isStopNode ? cleanAttrName : resolveTagName(cleanAttrName, true, options, matcher, xmlVersion);
15912
17211
  let attrVal;
15913
17212
  if (isStopNode) attrVal = attrMap[attr];
15914
17213
  else {
15915
17214
  attrVal = options.attributeValueProcessor(attr, attrMap[attr]);
15916
17215
  attrVal = orderedJs2Xml_replaceEntitiesValue(attrVal, options);
15917
17216
  }
15918
- if (true === attrVal && options.suppressBooleanAttributes) attrStr += ` ${attr.substr(options.attributeNamePrefix.length)}`;
15919
- else attrStr += ` ${attr.substr(options.attributeNamePrefix.length)}="${attrVal}"`;
17217
+ if (true === attrVal && options.suppressBooleanAttributes) attrStr += ` ${resolvedAttrName}`;
17218
+ else attrStr += ` ${resolvedAttrName}="${escapeAttribute(attrVal)}"`;
15920
17219
  }
15921
17220
  return attrStr;
15922
17221
  }
@@ -15988,7 +17287,8 @@
15988
17287
  stopNodes: [],
15989
17288
  oneListGroup: false,
15990
17289
  maxNestedTags: 100,
15991
- jPath: true
17290
+ jPath: true,
17291
+ sanitizeName: false
15992
17292
  };
15993
17293
  function Builder(options) {
15994
17294
  this.options = Object.assign({}, fxb_defaultOptions, options);
@@ -16008,7 +17308,7 @@
16008
17308
  else {
16009
17309
  this.ignoreAttributesFn = ignoreAttributes_getIgnoreAttributesFn(this.options.ignoreAttributes);
16010
17310
  this.attrPrefixLen = this.options.attributeNamePrefix.length;
16011
- this.isAttribute = isAttribute;
17311
+ this.isAttribute = fxb_isAttribute;
16012
17312
  }
16013
17313
  this.processTextOrObjNode = processTextOrObjNode;
16014
17314
  if (this.options.format) {
@@ -16023,6 +17323,28 @@
16023
17323
  this.newLine = '';
16024
17324
  }
16025
17325
  }
17326
+ function detectXmlVersionFromObj(jObj, options) {
17327
+ const decl = jObj['?xml'];
17328
+ if (decl && 'object' == typeof decl) {
17329
+ if (options.attributesGroupName && decl[options.attributesGroupName]) {
17330
+ const v = decl[options.attributesGroupName][options.attributeNamePrefix + 'version'];
17331
+ if (v) return v;
17332
+ }
17333
+ const v = decl[options.attributeNamePrefix + 'version'];
17334
+ if (v) return v;
17335
+ }
17336
+ return '1.0';
17337
+ }
17338
+ function fxb_resolveTagName(name, isAttribute, options, matcher, xmlVersion) {
17339
+ if (!options.sanitizeName) return name;
17340
+ if (qName(name, {
17341
+ xmlVersion
17342
+ })) return name;
17343
+ return options.sanitizeName(name, {
17344
+ isAttribute,
17345
+ matcher: matcher.readOnly()
17346
+ });
17347
+ }
16026
17348
  Builder.prototype.build = function(jObj) {
16027
17349
  if (this.options.preserveOrder) return toXml(jObj, this.options);
16028
17350
  {
@@ -16030,76 +17352,87 @@
16030
17352
  [this.options.arrayNodeName]: jObj
16031
17353
  };
16032
17354
  const matcher = new Matcher();
16033
- return this.j2x(jObj, 0, matcher).val;
17355
+ const xmlVersion = detectXmlVersionFromObj(jObj, this.options);
17356
+ return this.j2x(jObj, 0, matcher, xmlVersion).val;
16034
17357
  }
16035
17358
  };
16036
- Builder.prototype.j2x = function(jObj, level, matcher) {
17359
+ Builder.prototype.j2x = function(jObj, level, matcher, xmlVersion) {
16037
17360
  let attrStr = '';
16038
17361
  let val = '';
16039
17362
  if (this.options.maxNestedTags && matcher.getDepth() >= this.options.maxNestedTags) throw new Error("Maximum nested tags exceeded");
16040
17363
  const jPath = this.options.jPath ? matcher.toString() : matcher;
16041
17364
  const isCurrentStopNode = this.checkStopNode(matcher);
16042
- for(let key in jObj)if (Object.prototype.hasOwnProperty.call(jObj, key)) if (void 0 === jObj[key]) {
16043
- if (this.isAttribute(key)) val += '';
16044
- } else if (null === jObj[key]) if (this.isAttribute(key)) val += '';
16045
- else if (key === this.options.cdataPropName) val += '';
16046
- else if ('?' === key[0]) val += this.indentate(level) + '<' + key + '?' + this.tagEndChar;
16047
- else val += this.indentate(level) + '<' + key + '/' + this.tagEndChar;
16048
- else if (jObj[key] instanceof Date) val += this.buildTextValNode(jObj[key], key, '', level, matcher);
16049
- else if ('object' != typeof jObj[key]) {
16050
- const attr = this.isAttribute(key);
16051
- if (attr && !this.ignoreAttributesFn(attr, jPath)) attrStr += this.buildAttrPairStr(attr, '' + jObj[key], isCurrentStopNode);
16052
- else if (!attr) if (key === this.options.textNodeName) {
16053
- let newval = this.options.tagValueProcessor(key, '' + jObj[key]);
16054
- val += this.replaceEntitiesValue(newval);
16055
- } else {
16056
- matcher.push(key);
16057
- const isStopNode = this.checkStopNode(matcher);
16058
- matcher.pop();
16059
- if (isStopNode) {
16060
- const textValue = '' + jObj[key];
16061
- if ('' === textValue) val += this.indentate(level) + '<' + key + this.closeTag(key) + this.tagEndChar;
16062
- else val += this.indentate(level) + '<' + key + '>' + textValue + '</' + key + this.tagEndChar;
16063
- } else val += this.buildTextValNode(jObj[key], key, '', level, matcher);
16064
- }
16065
- } else if (Array.isArray(jObj[key])) {
16066
- const arrLen = jObj[key].length;
16067
- let listTagVal = "";
16068
- let listTagAttr = "";
16069
- for(let j = 0; j < arrLen; j++){
16070
- const item = jObj[key][j];
16071
- if (void 0 === item) ;
16072
- else if (null === item) if ("?" === key[0]) val += this.indentate(level) + '<' + key + '?' + this.tagEndChar;
16073
- else val += this.indentate(level) + '<' + key + '/' + this.tagEndChar;
16074
- else if ('object' == typeof item) if (this.options.oneListGroup) {
16075
- matcher.push(key);
16076
- const result = this.j2x(item, level + 1, matcher);
16077
- matcher.pop();
16078
- listTagVal += result.val;
16079
- if (this.options.attributesGroupName && item.hasOwnProperty(this.options.attributesGroupName)) listTagAttr += result.attrStr;
16080
- } else listTagVal += this.processTextOrObjNode(item, key, level, matcher);
16081
- else if (this.options.oneListGroup) {
16082
- let textValue = this.options.tagValueProcessor(key, item);
16083
- textValue = this.replaceEntitiesValue(textValue);
16084
- listTagVal += textValue;
17365
+ for(let key in jObj){
17366
+ if (!Object.prototype.hasOwnProperty.call(jObj, key)) continue;
17367
+ const isSpecialKey = key === this.options.textNodeName || key === this.options.cdataPropName || key === this.options.commentPropName || this.options.attributesGroupName && key === this.options.attributesGroupName || this.isAttribute(key) || '?' === key[0];
17368
+ const resolvedKey = isSpecialKey ? key : fxb_resolveTagName(key, false, this.options, matcher, xmlVersion);
17369
+ if (void 0 === jObj[key]) {
17370
+ if (this.isAttribute(key)) val += '';
17371
+ } else if (null === jObj[key]) if (this.isAttribute(key)) val += '';
17372
+ else if (resolvedKey === this.options.cdataPropName || resolvedKey === this.options.commentPropName) val += '';
17373
+ else if ('?' === resolvedKey[0]) val += this.indentate(level) + '<' + resolvedKey + '?' + this.tagEndChar;
17374
+ else val += this.indentate(level) + '<' + resolvedKey + '/' + this.tagEndChar;
17375
+ else if (jObj[key] instanceof Date) val += this.buildTextValNode(jObj[key], resolvedKey, '', level, matcher);
17376
+ else if ('object' != typeof jObj[key]) {
17377
+ const attr = this.isAttribute(key);
17378
+ if (attr && !this.ignoreAttributesFn(attr, jPath)) {
17379
+ const resolvedAttr = fxb_resolveTagName(attr, true, this.options, matcher, xmlVersion);
17380
+ attrStr += this.buildAttrPairStr(resolvedAttr, '' + jObj[key], isCurrentStopNode);
17381
+ } else if (!attr) if (key === this.options.textNodeName) {
17382
+ let newval = this.options.tagValueProcessor(key, '' + jObj[key]);
17383
+ val += this.replaceEntitiesValue(newval);
16085
17384
  } else {
16086
- matcher.push(key);
17385
+ matcher.push(resolvedKey);
16087
17386
  const isStopNode = this.checkStopNode(matcher);
16088
17387
  matcher.pop();
16089
17388
  if (isStopNode) {
16090
- const textValue = '' + item;
16091
- if ('' === textValue) listTagVal += this.indentate(level) + '<' + key + this.closeTag(key) + this.tagEndChar;
16092
- else listTagVal += this.indentate(level) + '<' + key + '>' + textValue + '</' + key + this.tagEndChar;
16093
- } else listTagVal += this.buildTextValNode(item, key, '', level, matcher);
16094
- }
16095
- }
16096
- if (this.options.oneListGroup) listTagVal = this.buildObjectNode(listTagVal, key, listTagAttr, level);
16097
- val += listTagVal;
16098
- } else if (this.options.attributesGroupName && key === this.options.attributesGroupName) {
16099
- const Ks = Object.keys(jObj[key]);
16100
- const L = Ks.length;
16101
- for(let j = 0; j < L; j++)attrStr += this.buildAttrPairStr(Ks[j], '' + jObj[key][Ks[j]], isCurrentStopNode);
16102
- } else val += this.processTextOrObjNode(jObj[key], key, level, matcher);
17389
+ const textValue = '' + jObj[key];
17390
+ if ('' === textValue) val += this.indentate(level) + '<' + resolvedKey + this.closeTag(resolvedKey) + this.tagEndChar;
17391
+ else val += this.indentate(level) + '<' + resolvedKey + '>' + textValue + '</' + resolvedKey + this.tagEndChar;
17392
+ } else val += this.buildTextValNode(jObj[key], resolvedKey, '', level, matcher);
17393
+ }
17394
+ } else if (Array.isArray(jObj[key])) {
17395
+ const arrLen = jObj[key].length;
17396
+ let listTagVal = "";
17397
+ let listTagAttr = "";
17398
+ for(let j = 0; j < arrLen; j++){
17399
+ const item = jObj[key][j];
17400
+ if (void 0 === item) ;
17401
+ else if (null === item) if ("?" === resolvedKey[0]) val += this.indentate(level) + '<' + resolvedKey + '?' + this.tagEndChar;
17402
+ else val += this.indentate(level) + '<' + resolvedKey + '/' + this.tagEndChar;
17403
+ else if ('object' == typeof item) if (this.options.oneListGroup) {
17404
+ matcher.push(resolvedKey);
17405
+ const result = this.j2x(item, level + 1, matcher, xmlVersion);
17406
+ matcher.pop();
17407
+ listTagVal += result.val;
17408
+ if (this.options.attributesGroupName && item.hasOwnProperty(this.options.attributesGroupName)) listTagAttr += result.attrStr;
17409
+ } else listTagVal += this.processTextOrObjNode(item, resolvedKey, level, matcher, xmlVersion);
17410
+ else if (this.options.oneListGroup) {
17411
+ let textValue = this.options.tagValueProcessor(resolvedKey, item);
17412
+ textValue = this.replaceEntitiesValue(textValue);
17413
+ listTagVal += textValue;
17414
+ } else {
17415
+ matcher.push(resolvedKey);
17416
+ const isStopNode = this.checkStopNode(matcher);
17417
+ matcher.pop();
17418
+ if (isStopNode) {
17419
+ const textValue = '' + item;
17420
+ if ('' === textValue) listTagVal += this.indentate(level) + '<' + resolvedKey + this.closeTag(resolvedKey) + this.tagEndChar;
17421
+ else listTagVal += this.indentate(level) + '<' + resolvedKey + '>' + textValue + '</' + resolvedKey + this.tagEndChar;
17422
+ } else listTagVal += this.buildTextValNode(item, resolvedKey, '', level, matcher);
17423
+ }
17424
+ }
17425
+ if (this.options.oneListGroup) listTagVal = this.buildObjectNode(listTagVal, resolvedKey, listTagAttr, level);
17426
+ val += listTagVal;
17427
+ } else if (this.options.attributesGroupName && key === this.options.attributesGroupName) {
17428
+ const Ks = Object.keys(jObj[key]);
17429
+ const L = Ks.length;
17430
+ for(let j = 0; j < L; j++){
17431
+ const resolvedAttr = fxb_resolveTagName(Ks[j], true, this.options, matcher, xmlVersion);
17432
+ attrStr += this.buildAttrPairStr(resolvedAttr, '' + jObj[key][Ks[j]], isCurrentStopNode);
17433
+ }
17434
+ } else val += this.processTextOrObjNode(jObj[key], resolvedKey, level, matcher, xmlVersion);
17435
+ }
16103
17436
  return {
16104
17437
  attrStr: attrStr,
16105
17438
  val: val
@@ -16111,9 +17444,9 @@
16111
17444
  val = this.replaceEntitiesValue(val);
16112
17445
  }
16113
17446
  if (this.options.suppressBooleanAttributes && "true" === val) return ' ' + attrName;
16114
- return ' ' + attrName + '="' + val + '"';
17447
+ return ' ' + attrName + '="' + escapeAttribute(val) + '"';
16115
17448
  };
16116
- function processTextOrObjNode(object, key, level, matcher) {
17449
+ function processTextOrObjNode(object, key, level, matcher, xmlVersion) {
16117
17450
  const attrValues = this.extractAttributes(object);
16118
17451
  matcher.push(key, attrValues);
16119
17452
  const isStopNode = this.checkStopNode(matcher);
@@ -16123,8 +17456,9 @@
16123
17456
  matcher.pop();
16124
17457
  return this.buildObjectNode(rawContent, key, attrStr, level);
16125
17458
  }
16126
- const result = this.j2x(object, level + 1, matcher);
17459
+ const result = this.j2x(object, level + 1, matcher, xmlVersion);
16127
17460
  matcher.pop();
17461
+ if ('?' === key[0]) return this.buildTextValNode('', key, result.attrStr, level, matcher);
16128
17462
  if (void 0 !== object[this.options.textNodeName] && 1 === Object.keys(object).length) return this.buildTextValNode(object[this.options.textNodeName], key, result.attrStr, level, matcher);
16129
17463
  return this.buildObjectNode(result.val, key, result.attrStr, level);
16130
17464
  }
@@ -16137,14 +17471,14 @@
16137
17471
  for(let attrKey in attrGroup){
16138
17472
  if (!Object.prototype.hasOwnProperty.call(attrGroup, attrKey)) continue;
16139
17473
  const cleanKey = attrKey.startsWith(this.options.attributeNamePrefix) ? attrKey.substring(this.options.attributeNamePrefix.length) : attrKey;
16140
- attrValues[cleanKey] = attrGroup[attrKey];
17474
+ attrValues[cleanKey] = escapeAttribute(attrGroup[attrKey]);
16141
17475
  hasAttrs = true;
16142
17476
  }
16143
17477
  } else for(let key in obj){
16144
17478
  if (!Object.prototype.hasOwnProperty.call(obj, key)) continue;
16145
17479
  const attr = this.isAttribute(key);
16146
17480
  if (attr) {
16147
- attrValues[attr] = obj[key];
17481
+ attrValues[attr] = escapeAttribute(obj[key]);
16148
17482
  hasAttrs = true;
16149
17483
  }
16150
17484
  }
@@ -16205,6 +17539,7 @@
16205
17539
  if ("" === val) if ("?" === key[0]) return this.indentate(level) + '<' + key + attrStr + '?' + this.tagEndChar;
16206
17540
  else return this.indentate(level) + '<' + key + attrStr + this.closeTag(key) + this.tagEndChar;
16207
17541
  {
17542
+ if ("?" === key[0]) return this.indentate(level) + '<' + key + attrStr + '?' + this.tagEndChar;
16208
17543
  let tagEndExp = '</' + key + this.tagEndChar;
16209
17544
  let piClosingChar = "";
16210
17545
  if ("?" === key[0]) {
@@ -16229,9 +17564,15 @@
16229
17564
  return false;
16230
17565
  };
16231
17566
  Builder.prototype.buildTextValNode = function(val, key, attrStr, level, matcher) {
16232
- if (false !== this.options.cdataPropName && key === this.options.cdataPropName) return this.indentate(level) + `<![CDATA[${val}]]>` + this.newLine;
17567
+ if (false !== this.options.cdataPropName && key === this.options.cdataPropName) {
17568
+ const safeVal = safeCdata(val);
17569
+ return this.indentate(level) + `<![CDATA[${safeVal}]]>` + this.newLine;
17570
+ }
17571
+ if (false !== this.options.commentPropName && key === this.options.commentPropName) {
17572
+ const safeVal = safeComment(val);
17573
+ return this.indentate(level) + `<!--${safeVal}-->` + this.newLine;
17574
+ }
16233
17575
  {
16234
- if (false !== this.options.commentPropName && key === this.options.commentPropName) return this.indentate(level) + `<!--${val}-->` + this.newLine;
16235
17576
  if ("?" === key[0]) return this.indentate(level) + '<' + key + attrStr + '?' + this.tagEndChar;
16236
17577
  let textValue = this.options.tagValueProcessor(key, val);
16237
17578
  textValue = this.replaceEntitiesValue(textValue);
@@ -16249,7 +17590,7 @@
16249
17590
  function indentate(level) {
16250
17591
  return this.options.indentBy.repeat(level);
16251
17592
  }
16252
- function isAttribute(name) {
17593
+ function fxb_isAttribute(name) {
16253
17594
  if (name.startsWith(this.options.attributeNamePrefix) && name !== this.options.textNodeName) return name.substr(this.attrPrefixLen);
16254
17595
  return false;
16255
17596
  }
@@ -16680,11 +18021,18 @@
16680
18021
  if (void 0 == globalThis[symbol]) {
16681
18022
  const te = new globalThis.TextEncoder();
16682
18023
  const td = new globalThis.TextDecoder();
18024
+ let tdStrict;
16683
18025
  globalThis[symbol] = {
16684
18026
  encodeUtf8 (text) {
16685
18027
  return te.encode(text);
16686
18028
  },
16687
- decodeUtf8 (bytes) {
18029
+ decodeUtf8 (bytes, strict) {
18030
+ if (strict) {
18031
+ if (void 0 === tdStrict) tdStrict = new globalThis.TextDecoder("utf-8", {
18032
+ fatal: true
18033
+ });
18034
+ return tdStrict.decode(bytes);
18035
+ }
16688
18036
  return td.decode(bytes);
16689
18037
  },
16690
18038
  checkUtf8 (text) {
@@ -16860,8 +18208,13 @@
16860
18208
  this.view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
16861
18209
  }
16862
18210
  tag() {
16863
- let tag = this.uint32(), fieldNo = tag >>> 3, wireType = 7 & tag;
16864
- if (fieldNo <= 0 || wireType < 0 || wireType > 5) throw new Error("illegal tag: field no " + fieldNo + " wire type " + wireType);
18211
+ const start = this.pos;
18212
+ const tag = this.uint32();
18213
+ const bytesRead = this.pos - start;
18214
+ if (bytesRead > 5 || 5 == bytesRead && this.buf[this.pos - 1] > 0x0f) throw new Error("illegal tag: varint overflows uint32");
18215
+ const fieldNo = tag >>> 3;
18216
+ const wireType = 7 & tag;
18217
+ if (fieldNo <= 0 || wireType > 5) throw new Error("illegal tag: field no " + fieldNo + " wire type " + wireType);
16865
18218
  return [
16866
18219
  fieldNo,
16867
18220
  wireType
@@ -16949,8 +18302,8 @@
16949
18302
  this.assertBounds();
16950
18303
  return this.buf.subarray(start, start + len);
16951
18304
  }
16952
- string() {
16953
- return this.decodeUtf8(this.bytes());
18305
+ string(strict) {
18306
+ return this.decodeUtf8(this.bytes(), strict);
16954
18307
  }
16955
18308
  }
16956
18309
  function assertInt32(arg) {
@@ -17700,7 +19053,7 @@
17700
19053
  var _a;
17701
19054
  switch(field.fieldKind){
17702
19055
  case "scalar":
17703
- message.set(field, readScalar(reader, field.scalar));
19056
+ message.set(field, readScalar(reader, field.scalar, field.utf8Validation));
17704
19057
  break;
17705
19058
  case "enum":
17706
19059
  const val = readScalar(reader, descriptors_ScalarType.INT32);
@@ -17742,12 +19095,12 @@
17742
19095
  const [fieldNo] = reader.tag();
17743
19096
  switch(fieldNo){
17744
19097
  case 1:
17745
- key = readScalar(reader, field.mapKey);
19098
+ key = readScalar(reader, field.mapKey, field.utf8Validation);
17746
19099
  break;
17747
19100
  case 2:
17748
19101
  switch(field.mapKind){
17749
19102
  case "scalar":
17750
- val = readScalar(reader, field.scalar);
19103
+ val = readScalar(reader, field.scalar, field.utf8Validation);
17751
19104
  break;
17752
19105
  case "enum":
17753
19106
  val = reader.int32();
@@ -17779,9 +19132,9 @@
17779
19132
  if ("message" === field.listKind) return void list.add(readMessageField(reader, options, field));
17780
19133
  const scalarType = null != (_a = field.scalar) ? _a : descriptors_ScalarType.INT32;
17781
19134
  const packed = wireType == binary_encoding_WireType.LengthDelimited && scalarType != descriptors_ScalarType.STRING && scalarType != descriptors_ScalarType.BYTES;
17782
- if (!packed) return void list.add(readScalar(reader, scalarType));
19135
+ if (!packed) return void list.add(readScalar(reader, scalarType, field.utf8Validation));
17783
19136
  const e = reader.uint32() + reader.pos;
17784
- while(reader.pos < e)list.add(readScalar(reader, scalarType));
19137
+ while(reader.pos < e)list.add(readScalar(reader, scalarType, field.utf8Validation));
17785
19138
  }
17786
19139
  function readMessageField(reader, options, field, mergeMessage) {
17787
19140
  const delimited = field.delimitedEncoding;
@@ -17789,10 +19142,10 @@
17789
19142
  readMessage(message, reader, options, delimited, delimited ? field.number : reader.uint32());
17790
19143
  return message;
17791
19144
  }
17792
- function readScalar(reader, type) {
19145
+ function readScalar(reader, type, validateUtf8 = false) {
17793
19146
  switch(type){
17794
19147
  case descriptors_ScalarType.STRING:
17795
- return reader.string();
19148
+ return reader.string(validateUtf8);
17796
19149
  case descriptors_ScalarType.BOOL:
17797
19150
  return reader.bool();
17798
19151
  case descriptors_ScalarType.DOUBLE:
@@ -18340,6 +19693,7 @@
18340
19693
  }
18341
19694
  const registry_EDITION_PROTO2 = 998;
18342
19695
  const registry_EDITION_PROTO3 = 999;
19696
+ const EDITION_UNSTABLE = 9999;
18343
19697
  const TYPE_STRING = 9;
18344
19698
  const TYPE_GROUP = 10;
18345
19699
  const TYPE_MESSAGE = 11;
@@ -18355,6 +19709,8 @@
18355
19709
  const PACKED = 1;
18356
19710
  const DELIMITED = 2;
18357
19711
  const OPEN = 1;
19712
+ const VERIFY = 2;
19713
+ const maximumEdition = 1001;
18358
19714
  const featureDefaults = {
18359
19715
  998: {
18360
19716
  fieldPresence: 1,
@@ -18617,6 +19973,7 @@
18617
19973
  message: void 0,
18618
19974
  enum: void 0,
18619
19975
  presence: getFieldPresence(proto, oneof, isExtension, parentOrFile),
19976
+ utf8Validation: isUtf8Validated(proto, parentOrFile),
18620
19977
  listKind: void 0,
18621
19978
  mapKind: void 0,
18622
19979
  mapKey: void 0,
@@ -18722,6 +20079,7 @@
18722
20079
  case "proto3":
18723
20080
  return registry_EDITION_PROTO3;
18724
20081
  case "editions":
20082
+ if (proto.edition === EDITION_UNSTABLE) return maximumEdition;
18725
20083
  if (proto.edition in featureDefaults) return proto.edition;
18726
20084
  throw new Error(`${proto.name}: unsupported edition`);
18727
20085
  default:
@@ -18814,6 +20172,12 @@
18814
20172
  parent
18815
20173
  });
18816
20174
  }
20175
+ function isUtf8Validated(proto, parent) {
20176
+ return VERIFY == resolveFeature("utf8Validation", {
20177
+ proto,
20178
+ parent
20179
+ });
20180
+ }
18817
20181
  function resolveFeature(name, ref) {
18818
20182
  var _a, _b;
18819
20183
  const featureSet = null == (_a = ref.proto.options) ? void 0 : _a.features;
@@ -19636,7 +21000,8 @@
19636
21000
  number: 10,
19637
21001
  type: 8,
19638
21002
  label: 1,
19639
- defaultValue: "false"
21003
+ defaultValue: "false",
21004
+ options: {}
19640
21005
  },
19641
21006
  {
19642
21007
  name: "java_generate_equals_and_hash",
@@ -20001,6 +21366,12 @@
20001
21366
  type: 14,
20002
21367
  label: 1,
20003
21368
  typeName: ".google.protobuf.Edition"
21369
+ },
21370
+ {
21371
+ name: "removal_error",
21372
+ number: 5,
21373
+ type: 9,
21374
+ label: 1
20004
21375
  }
20005
21376
  ]
20006
21377
  }
@@ -21210,7 +22581,7 @@
21210
22581
  function timestamp_timestampMs(timestamp) {
21211
22582
  return 1000 * Number(timestamp.seconds) + Math.round(timestamp.nanos / 1000000);
21212
22583
  }
21213
- var package_namespaceObject = JSON.parse('{"UU":"@dan-uni/dan-any","rE":"1.4.4","TB":"https://github.com/ani-uni/danuni/tree/master/packages/dan-any#readme"}');
22584
+ var package_namespaceObject = JSON.parse('{"UU":"@dan-uni/dan-any","rE":"1.4.6","TB":"https://github.com/ani-uni/danuni/tree/master/packages/dan-any#readme"}');
21214
22585
  const color_pad = (s)=>s.length < 2 ? `0${s}` : s;
21215
22586
  const decimalToHex = (n)=>color_pad(n.toString(16));
21216
22587
  const isDarkColor = ({ r, g, b })=>0.299 * r + 0.587 * g + 0.114 * b < 0x30;
@@ -25169,7 +26540,11 @@
25169
26540
  }
25170
26541
  static fromBiliXML(xml, options) {
25171
26542
  const parser = new XMLParser({
25172
- ignoreAttributes: false
26543
+ ignoreAttributes: false,
26544
+ isArray: (_name, jpath, _isLeafNode, _isAttribute)=>{
26545
+ if ('i.d' === jpath) return true;
26546
+ return false;
26547
+ }
25173
26548
  });
25174
26549
  const oriData = parser.parse(xml);
25175
26550
  const dans = oriData.i.d;