@intlify/core 12.0.0-alpha.6 → 12.0.0-alpha.8

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.
@@ -1,11 +1,11 @@
1
1
  /**
2
- * @intlify/core v12.0.0-alpha.6
2
+ * @intlify/core v12.0.0-alpha.8
3
3
  * (c) 2016-present kazuya kawaguchi and contributors
4
4
  * @license MIT
5
5
  **/
6
6
  var IntlifyCore = (function(exports) {
7
7
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
8
- //#region packages/shared/src/utils.ts
8
+ // packages/shared/src/utils.ts
9
9
  /**
10
10
  * Original Utilities
11
11
  * written by kazuya kawaguchi
@@ -125,8 +125,7 @@ var IntlifyCore = (function(exports) {
125
125
  }
126
126
  return res.join("\n");
127
127
  }
128
- //#endregion
129
- //#region packages/shared/src/warn.ts
128
+ // packages/shared/src/warn.ts
130
129
  function warn(msg, err) {
131
130
  if (typeof console !== "undefined") {
132
131
  console.warn(`[intlify] ` + msg);
@@ -141,8 +140,7 @@ var IntlifyCore = (function(exports) {
141
140
  warn(msg);
142
141
  }
143
142
  }
144
- //#endregion
145
- //#region packages/shared/src/sanitize.ts
143
+ // packages/shared/src/sanitize.ts
146
144
  function escapeHtml(rawText) {
147
145
  return rawText.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;").replace(/\//g, "&#x2F;").replace(/=/g, "&#x3D;");
148
146
  }
@@ -150,7 +148,7 @@ var IntlifyCore = (function(exports) {
150
148
  return value.replace(/&(?![a-z0-9#]{2,6};)/gi, "&amp;").replace(/"/g, "&quot;").replace(/'/g, "&apos;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
151
149
  }
152
150
  const javascriptSchemePattern = /^javascript:/i;
153
- const urlAttributePattern = /^(?:href|src|action|formaction)$/i;
151
+ const urlAttributePattern = /^(?:href|xlink:href|src|action|formaction)$/i;
154
152
  const numericCharacterReferencePattern = /&#(?:x([0-9a-f]+)|(\d+));?/gi;
155
153
  const namedWhitespaceCharacterReferencePattern = /&(?:Tab|NewLine);/g;
156
154
  const colonCharacterReferencePattern = /&colon;?/gi;
@@ -159,7 +157,9 @@ var IntlifyCore = (function(exports) {
159
157
  const eventHandlerAttributePattern = /(^|[\s"'<>/])on(\w+\s*=)/gi;
160
158
  const srcdocPattern = /(?:^|[\s"'<>/])srcdoc\s*=/i;
161
159
  const srcdocAttributePattern = /(^|[\s"'<>/])s(rcdoc\s*=)/gi;
162
- const unquotedUrlAttributePattern = /(^|[\s"'<>/])((?:href|src|action|formaction)\s*=\s*)([^\s"'=<>`]+)/gi;
160
+ const dangerousElementPattern = /<(?:base|animate|set)(?=[\s/>]|$)/i;
161
+ const dangerousElementStartTagPattern = /<(base|animate|set)(?=[\s/>]|$)/gi;
162
+ const unquotedUrlAttributePattern = /(^|[\s"'<>/])((?:href|xlink:href|src|action|formaction)\s*=\s*)([^\s"'=<>`]+)/gi;
163
163
  function decodeNumericCharacterReference(match, hex, decimal) {
164
164
  const digits = hex || decimal;
165
165
  if (!digits) return match;
@@ -218,11 +218,14 @@ var IntlifyCore = (function(exports) {
218
218
  warn("Potentially dangerous srcdoc attribute detected in translation. Consider removing srcdoc from your translation messages.");
219
219
  html = html.replace(srcdocAttributePattern, "$1&#115;$2");
220
220
  }
221
+ if (dangerousElementPattern.test(html)) {
222
+ warn("Potentially dangerous element (<base>, <animate> or <set>) detected in translation. Consider removing it from your translation messages.");
223
+ html = html.replace(dangerousElementStartTagPattern, "&lt;$1");
224
+ }
221
225
  html = html.replace(unquotedUrlAttributePattern, (match, boundary, prefix, attrValue) => hasJavascriptScheme(attrValue) ? `${boundary}${prefix}about:blank` : match);
222
226
  return html;
223
227
  }
224
- //#endregion
225
- //#region packages/shared/src/messages.ts
228
+ // packages/shared/src/messages.ts
226
229
  const isNotObjectOrIsArray = (val) => !isObject(val) || isArray(val);
227
230
  function deepCopy(src, des) {
228
231
  if (isNotObjectOrIsArray(src) || isNotObjectOrIsArray(des) || des === Object.prototype) throw new Error("Invalid value");
@@ -252,8 +255,7 @@ var IntlifyCore = (function(exports) {
252
255
  }
253
256
  }
254
257
  }
255
- //#endregion
256
- //#region packages/message-compiler/src/errors.ts
258
+ // packages/message-compiler/src/errors.ts
257
259
  const CompileErrorCodes = {
258
260
  EXPECTED_TOKEN: 1,
259
261
  INVALID_TOKEN_IN_PLACEHOLDER: 2,
@@ -300,8 +302,7 @@ var IntlifyCore = (function(exports) {
300
302
  error.domain = domain;
301
303
  return error;
302
304
  }
303
- //#endregion
304
- //#region packages/core-base/src/ast.ts
305
+ // packages/core-base/src/ast.ts
305
306
  function isMessageAST(val) {
306
307
  return isObject(val) && resolveType(val) === 0 && (hasOwn(val, "b") || hasOwn(val, "body"));
307
308
  }
@@ -361,8 +362,7 @@ var IntlifyCore = (function(exports) {
361
362
  function createUnhandleNodeError(type) {
362
363
  return /* @__PURE__ */ new Error(`unhandled node type: ${type}`);
363
364
  }
364
- //#endregion
365
- //#region packages/core-base/src/format.ts
365
+ // packages/core-base/src/format.ts
366
366
  function format(ast) {
367
367
  return (ctx) => formatParts(ctx, ast);
368
368
  }
@@ -410,8 +410,7 @@ var IntlifyCore = (function(exports) {
410
410
  default: throw new Error(`unhandled node on format message part: ${type}`);
411
411
  }
412
412
  }
413
- //#endregion
414
- //#region packages/core-base/src/compilation.ts
413
+ // packages/core-base/src/compilation.ts
415
414
  let compileCache = create();
416
415
  function clearCompileCache() {
417
416
  compileCache = create();
@@ -431,8 +430,7 @@ var IntlifyCore = (function(exports) {
431
430
  } else return format(message);
432
431
  }
433
432
  }
434
- //#endregion
435
- //#region packages/core-base/src/errors.ts
433
+ // packages/core-base/src/errors.ts
436
434
  const CoreErrorCodes = {
437
435
  INVALID_ARGUMENT: 17,
438
436
  INVALID_DATE_ARGUMENT: 18,
@@ -454,8 +452,7 @@ var IntlifyCore = (function(exports) {
454
452
  [CoreErrorCodes.NOT_SUPPORT_LOCALE_ASYNC_FUNCTION]: "cannot support async function",
455
453
  [CoreErrorCodes.NOT_SUPPORT_LOCALE_TYPE]: "cannot support locale type"
456
454
  };
457
- //#endregion
458
- //#region packages/core-base/src/fallbacker.ts
455
+ // packages/core-base/src/fallbacker.ts
459
456
  /** @internal */
460
457
  function getLocale(context, options) {
461
458
  return options.locale != null ? resolveLocale(options.locale) : resolveLocale(context.locale);
@@ -571,8 +568,7 @@ var IntlifyCore = (function(exports) {
571
568
  }
572
569
  return follow;
573
570
  }
574
- //#endregion
575
- //#region packages/core-base/src/resolver.ts
571
+ // packages/core-base/src/resolver.ts
576
572
  const pathStateMachine = [];
577
573
  pathStateMachine[0] = {
578
574
  ["w"]: [0],
@@ -795,8 +791,7 @@ var IntlifyCore = (function(exports) {
795
791
  }
796
792
  return last;
797
793
  }
798
- //#endregion
799
- //#region packages/core-base/src/warnings.ts
794
+ // packages/core-base/src/warnings.ts
800
795
  const CoreWarnCodes = {
801
796
  NOT_FOUND_KEY: 1,
802
797
  FALLBACK_TO_TRANSLATE: 2,
@@ -830,13 +825,12 @@ var IntlifyCore = (function(exports) {
830
825
  function getWarnMessage(code, ...args) {
831
826
  return format$1(warnMessages[code], ...args);
832
827
  }
833
- //#endregion
834
- //#region packages/core-base/src/context.ts
828
+ // packages/core-base/src/context.ts
835
829
  /**
836
830
  * Intlify core-base version
837
831
  * @internal
838
832
  */
839
- const VERSION = "12.0.0-alpha.6";
833
+ const VERSION = "12.0.0-alpha.8";
840
834
  const NOT_RESOLVED = -1;
841
835
  const DEFAULT_LOCALE = "en-US";
842
836
  const MISSING_RESOLVE_VALUE = "";
@@ -1040,8 +1034,7 @@ var IntlifyCore = (function(exports) {
1040
1034
  for (let i = index + 1; i < locales.length; i++) if (isAlmostSameLocale(targetLocale, locales[i])) return true;
1041
1035
  return false;
1042
1036
  }
1043
- //#endregion
1044
- //#region packages/core-base/src/formatter.ts
1037
+ // packages/core-base/src/formatter.ts
1045
1038
  function resolveFormatLocale(context, key, locale, formats, missingWarn, fallbackWarn, type) {
1046
1039
  const { fallbackLocale, localeFallbacker, onWarn } = context;
1047
1040
  const locales = localeFallbacker(context, fallbackLocale, locale);
@@ -1149,15 +1142,13 @@ var IntlifyCore = (function(exports) {
1149
1142
  if (isPlainObject(arg4)) overrides = arg4;
1150
1143
  return overrides;
1151
1144
  }
1152
- //#endregion
1153
- //#region packages/core-base/src/intl.ts
1145
+ // packages/core-base/src/intl.ts
1154
1146
  const intlDefined = typeof Intl !== "undefined";
1155
1147
  const Availabilities = {
1156
1148
  dateTimeFormat: intlDefined && typeof Intl.DateTimeFormat !== "undefined",
1157
1149
  numberFormat: intlDefined && typeof Intl.NumberFormat !== "undefined"
1158
1150
  };
1159
- //#endregion
1160
- //#region packages/core-base/src/datetime.ts
1151
+ // packages/core-base/src/datetime.ts
1161
1152
  function datetime(context, ...args) {
1162
1153
  const { datetimeFormats, onWarn } = context;
1163
1154
  const { __datetimeFormatters } = context;
@@ -1227,8 +1218,7 @@ var IntlifyCore = (function(exports) {
1227
1218
  function clearDateTimeFormat(ctx, locale, format) {
1228
1219
  clearFormatCache(ctx.__datetimeFormatters, locale, format);
1229
1220
  }
1230
- //#endregion
1231
- //#region packages/core-base/src/number.ts
1221
+ // packages/core-base/src/number.ts
1232
1222
  function number(context, ...args) {
1233
1223
  const { numberFormats, onWarn } = context;
1234
1224
  const { __numberFormatters } = context;
@@ -1284,8 +1274,7 @@ var IntlifyCore = (function(exports) {
1284
1274
  function clearNumberFormat(ctx, locale, format) {
1285
1275
  clearFormatCache(ctx.__numberFormatters, locale, format);
1286
1276
  }
1287
- //#endregion
1288
- //#region packages/core-base/src/runtime.ts
1277
+ // packages/core-base/src/runtime.ts
1289
1278
  const DEFAULT_MODIFIER = (str) => str;
1290
1279
  const DEFAULT_MESSAGE = (_ctx) => "";
1291
1280
  const DEFAULT_MESSAGE_DATA_TYPE = "text";
@@ -1402,8 +1391,7 @@ var IntlifyCore = (function(exports) {
1402
1391
  };
1403
1392
  return ctx;
1404
1393
  }
1405
- //#endregion
1406
- //#region packages/core-base/src/translate.ts
1394
+ // packages/core-base/src/translate.ts
1407
1395
  const NOOP_MESSAGE_FUNCTION = () => "";
1408
1396
  const isMessageFunction = (val) => isFunction(val);
1409
1397
  /** @internal */
@@ -1633,7 +1621,6 @@ var IntlifyCore = (function(exports) {
1633
1621
  pluralIndex: isNumber(options.plural) ? options.plural : void 0
1634
1622
  };
1635
1623
  }
1636
- //#endregion
1637
1624
  exports.AST_NODE_PROPS_KEYS = AST_NODE_PROPS_KEYS;
1638
1625
  exports.CORE_ERROR_CODES_EXTEND_POINT = CORE_ERROR_CODES_EXTEND_POINT;
1639
1626
  exports.CORE_WARN_CODES_EXTEND_POINT = CORE_WARN_CODES_EXTEND_POINT;