@intlify/core-base 9.14.3 → 9.14.5

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,5 +1,5 @@
1
1
  /*!
2
- * core-base v9.14.3
2
+ * core-base v9.14.5
3
3
  * (c) 2025 kazuya kawaguchi
4
4
  * Released under the MIT License.
5
5
  */
@@ -8,6 +8,80 @@
8
8
  var messageCompiler = require('@intlify/message-compiler');
9
9
  var shared = require('@intlify/shared');
10
10
 
11
+ function isMessageAST(val) {
12
+ return (shared.isObject(val) &&
13
+ resolveType(val) === 0 &&
14
+ (shared.hasOwn(val, 'b') || shared.hasOwn(val, 'body')));
15
+ }
16
+ const PROPS_BODY = ['b', 'body'];
17
+ function resolveBody(node) {
18
+ return resolveProps(node, PROPS_BODY);
19
+ }
20
+ const PROPS_CASES = ['c', 'cases'];
21
+ function resolveCases(node) {
22
+ return resolveProps(node, PROPS_CASES, []);
23
+ }
24
+ const PROPS_STATIC = ['s', 'static'];
25
+ function resolveStatic(node) {
26
+ return resolveProps(node, PROPS_STATIC);
27
+ }
28
+ const PROPS_ITEMS = ['i', 'items'];
29
+ function resolveItems(node) {
30
+ return resolveProps(node, PROPS_ITEMS, []);
31
+ }
32
+ const PROPS_TYPE = ['t', 'type'];
33
+ function resolveType(node) {
34
+ return resolveProps(node, PROPS_TYPE);
35
+ }
36
+ const PROPS_VALUE = ['v', 'value'];
37
+ function resolveValue$1(node, type) {
38
+ const resolved = resolveProps(node, PROPS_VALUE);
39
+ if (resolved != null) {
40
+ return resolved;
41
+ }
42
+ else {
43
+ throw createUnhandleNodeError(type);
44
+ }
45
+ }
46
+ const PROPS_MODIFIER = ['m', 'modifier'];
47
+ function resolveLinkedModifier(node) {
48
+ return resolveProps(node, PROPS_MODIFIER);
49
+ }
50
+ const PROPS_KEY = ['k', 'key'];
51
+ function resolveLinkedKey(node) {
52
+ const resolved = resolveProps(node, PROPS_KEY);
53
+ if (resolved) {
54
+ return resolved;
55
+ }
56
+ else {
57
+ throw createUnhandleNodeError(6 /* NodeTypes.Linked */);
58
+ }
59
+ }
60
+ function resolveProps(node, props, defaultValue) {
61
+ for (let i = 0; i < props.length; i++) {
62
+ const prop = props[i];
63
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
64
+ if (shared.hasOwn(node, prop) && node[prop] != null) {
65
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
66
+ return node[prop];
67
+ }
68
+ }
69
+ return defaultValue;
70
+ }
71
+ const AST_NODE_PROPS_KEYS = [
72
+ ...PROPS_BODY,
73
+ ...PROPS_CASES,
74
+ ...PROPS_STATIC,
75
+ ...PROPS_ITEMS,
76
+ ...PROPS_KEY,
77
+ ...PROPS_MODIFIER,
78
+ ...PROPS_VALUE,
79
+ ...PROPS_TYPE
80
+ ];
81
+ function createUnhandleNodeError(type) {
82
+ return new Error(`unhandled node type: ${type}`);
83
+ }
84
+
11
85
  const pathStateMachine = [];
12
86
  pathStateMachine[0 /* States.BEFORE_PATH */] = {
13
87
  ["w" /* PathCharTypes.WORKSPACE */]: [0 /* States.BEFORE_PATH */],
@@ -241,7 +315,7 @@ function resolveWithKeyValue(obj, path) {
241
315
  *
242
316
  * @VueI18nGeneral
243
317
  */
244
- function resolveValue$1(obj, path) {
318
+ function resolveValue(obj, path) {
245
319
  // check object
246
320
  if (!shared.isObject(obj)) {
247
321
  return null;
@@ -263,7 +337,16 @@ function resolveValue$1(obj, path) {
263
337
  let last = obj;
264
338
  let i = 0;
265
339
  while (i < len) {
266
- const val = last[hit[i]];
340
+ const key = hit[i];
341
+ /**
342
+ * NOTE:
343
+ * if `key` is intlify message format AST node key and `last` is intlify message format AST, skip it.
344
+ * because the AST node is not a key-value structure.
345
+ */
346
+ if (AST_NODE_PROPS_KEYS.includes(key) && isMessageAST(last)) {
347
+ return null;
348
+ }
349
+ const val = last[key];
267
350
  if (val === undefined) {
268
351
  return null;
269
352
  }
@@ -635,7 +718,7 @@ function appendItemToChain(chain, target, blocks) {
635
718
  * Intlify core-base version
636
719
  * @internal
637
720
  */
638
- const VERSION = '9.14.3';
721
+ const VERSION = '9.14.5';
639
722
  const NOT_REOSLVED = -1;
640
723
  const DEFAULT_LOCALE = 'en-US';
641
724
  const MISSING_RESOLVE_VALUE = '';
@@ -878,14 +961,6 @@ function formatParts(ctx, ast) {
878
961
  return formatMessageParts(ctx, body);
879
962
  }
880
963
  }
881
- const PROPS_BODY = ['b', 'body'];
882
- function resolveBody(node) {
883
- return resolveProps(node, PROPS_BODY);
884
- }
885
- const PROPS_CASES = ['c', 'cases'];
886
- function resolveCases(node) {
887
- return resolveProps(node, PROPS_CASES, []);
888
- }
889
964
  function formatMessageParts(ctx, node) {
890
965
  const static_ = resolveStatic(node);
891
966
  if (static_ != null) {
@@ -898,22 +973,14 @@ function formatMessageParts(ctx, node) {
898
973
  return ctx.normalize(messages);
899
974
  }
900
975
  }
901
- const PROPS_STATIC = ['s', 'static'];
902
- function resolveStatic(node) {
903
- return resolveProps(node, PROPS_STATIC);
904
- }
905
- const PROPS_ITEMS = ['i', 'items'];
906
- function resolveItems(node) {
907
- return resolveProps(node, PROPS_ITEMS, []);
908
- }
909
976
  function formatMessagePart(ctx, node) {
910
977
  const type = resolveType(node);
911
978
  switch (type) {
912
979
  case 3 /* NodeTypes.Text */: {
913
- return resolveValue(node, type);
980
+ return resolveValue$1(node, type);
914
981
  }
915
982
  case 9 /* NodeTypes.Literal */: {
916
- return resolveValue(node, type);
983
+ return resolveValue$1(node, type);
917
984
  }
918
985
  case 4 /* NodeTypes.Named */: {
919
986
  const named = node;
@@ -942,68 +1009,21 @@ function formatMessagePart(ctx, node) {
942
1009
  return ctx.linked(formatMessagePart(ctx, key), modifier ? formatMessagePart(ctx, modifier) : undefined, ctx.type);
943
1010
  }
944
1011
  case 7 /* NodeTypes.LinkedKey */: {
945
- return resolveValue(node, type);
1012
+ return resolveValue$1(node, type);
946
1013
  }
947
1014
  case 8 /* NodeTypes.LinkedModifier */: {
948
- return resolveValue(node, type);
1015
+ return resolveValue$1(node, type);
949
1016
  }
950
1017
  default:
951
1018
  throw new Error(`unhandled node on format message part: ${type}`);
952
1019
  }
953
1020
  }
954
- const PROPS_TYPE = ['t', 'type'];
955
- function resolveType(node) {
956
- return resolveProps(node, PROPS_TYPE);
957
- }
958
- const PROPS_VALUE = ['v', 'value'];
959
- function resolveValue(node, type) {
960
- const resolved = resolveProps(node, PROPS_VALUE);
961
- if (resolved) {
962
- return resolved;
963
- }
964
- else {
965
- throw createUnhandleNodeError(type);
966
- }
967
- }
968
- const PROPS_MODIFIER = ['m', 'modifier'];
969
- function resolveLinkedModifier(node) {
970
- return resolveProps(node, PROPS_MODIFIER);
971
- }
972
- const PROPS_KEY = ['k', 'key'];
973
- function resolveLinkedKey(node) {
974
- const resolved = resolveProps(node, PROPS_KEY);
975
- if (resolved) {
976
- return resolved;
977
- }
978
- else {
979
- throw createUnhandleNodeError(6 /* NodeTypes.Linked */);
980
- }
981
- }
982
- function resolveProps(node, props, defaultValue) {
983
- for (let i = 0; i < props.length; i++) {
984
- const prop = props[i];
985
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
986
- if (shared.hasOwn(node, prop) && node[prop] != null) {
987
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
988
- return node[prop];
989
- }
990
- }
991
- return defaultValue;
992
- }
993
- function createUnhandleNodeError(type) {
994
- return new Error(`unhandled node type: ${type}`);
995
- }
996
1021
 
997
1022
  const defaultOnCacheKey = (message) => message;
998
1023
  let compileCache = shared.create();
999
1024
  function clearCompileCache() {
1000
1025
  compileCache = shared.create();
1001
1026
  }
1002
- function isMessageAST(val) {
1003
- return (shared.isObject(val) &&
1004
- resolveType(val) === 0 &&
1005
- (shared.hasOwn(val, 'b') || shared.hasOwn(val, 'body')));
1006
- }
1007
1027
  function baseCompile(message, options = {}) {
1008
1028
  // error detecting on compile
1009
1029
  let detectError = false;
@@ -1166,9 +1186,13 @@ function translate(context, ...args) {
1166
1186
  const msgContext = createMessageContext(ctxOptions);
1167
1187
  const messaged = evaluateMessage(context, msg, msgContext);
1168
1188
  // if use post translation option, proceed it with handler
1169
- const ret = postTranslation
1189
+ let ret = postTranslation
1170
1190
  ? postTranslation(messaged, key)
1171
1191
  : messaged;
1192
+ // apply HTML sanitization for security
1193
+ if (escapeParameter && shared.isString(ret)) {
1194
+ ret = shared.sanitizeTranslatedHtml(ret);
1195
+ }
1172
1196
  return ret;
1173
1197
  }
1174
1198
  function escapeParams(options) {
@@ -1600,6 +1624,7 @@ function clearNumberFormat(ctx, locale, format) {
1600
1624
 
1601
1625
  exports.CompileErrorCodes = messageCompiler.CompileErrorCodes;
1602
1626
  exports.createCompileError = messageCompiler.createCompileError;
1627
+ exports.AST_NODE_PROPS_KEYS = AST_NODE_PROPS_KEYS;
1603
1628
  exports.CoreErrorCodes = CoreErrorCodes;
1604
1629
  exports.CoreWarnCodes = CoreWarnCodes;
1605
1630
  exports.DATETIME_FORMAT_OPTIONS_KEYS = DATETIME_FORMAT_OPTIONS_KEYS;
@@ -1642,7 +1667,7 @@ exports.registerLocaleFallbacker = registerLocaleFallbacker;
1642
1667
  exports.registerMessageCompiler = registerMessageCompiler;
1643
1668
  exports.registerMessageResolver = registerMessageResolver;
1644
1669
  exports.resolveLocale = resolveLocale;
1645
- exports.resolveValue = resolveValue$1;
1670
+ exports.resolveValue = resolveValue;
1646
1671
  exports.resolveWithKeyValue = resolveWithKeyValue;
1647
1672
  exports.setAdditionalMeta = setAdditionalMeta;
1648
1673
  exports.setDevToolsHook = setDevToolsHook;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intlify/core-base",
3
- "version": "9.14.3",
3
+ "version": "9.14.5",
4
4
  "description": "@intlify/core-base",
5
5
  "keywords": [
6
6
  "core",
@@ -33,12 +33,12 @@
33
33
  "jsdelivr": "dist/core-base.global.js",
34
34
  "types": "dist/core-base.d.ts",
35
35
  "dependencies": {
36
- "@intlify/message-compiler": "9.14.3",
37
- "@intlify/shared": "9.14.3"
36
+ "@intlify/shared": "9.14.5",
37
+ "@intlify/message-compiler": "9.14.5"
38
38
  },
39
39
  "devDependencies": {
40
- "@intlify/devtools-if": "9.14.3",
41
- "@intlify/vue-devtools": "9.14.3"
40
+ "@intlify/devtools-if": "9.14.5",
41
+ "@intlify/vue-devtools": "9.14.5"
42
42
  },
43
43
  "engines": {
44
44
  "node": ">= 16"