vue-i18n 11.4.20 → 11.4.22

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.
package/dist/vue-i18n.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * vue-i18n v11.4.20
2
+ * vue-i18n v11.4.22
3
3
  * (c) 2026 kazuya kawaguchi
4
4
  * Released under the MIT License.
5
5
  */
@@ -30,7 +30,7 @@ var Vue__namespace = /*#__PURE__*/_interopNamespaceDefault(Vue);
30
30
  *
31
31
  * @VueI18nGeneral
32
32
  */
33
- const VERSION = '11.4.20';
33
+ const VERSION = '11.4.22';
34
34
 
35
35
  const I18nErrorCodes = {
36
36
  // composer module errors
@@ -884,6 +884,7 @@ export declare interface ComposerOptions<Schema extends {
884
884
  * Whether to escape parameters for list or named interpolation values.
885
885
  * When enabled, this option:
886
886
  * - Escapes HTML special characters (`<`, `>`, `"`, `'`, `&`, `/`, `=`) in interpolation parameters
887
+ * - Escapes the text of interpolation parameters that are not strings, such as arrays and objects
887
888
  * - Sanitizes the final translated HTML to prevent XSS attacks by:
888
889
  * - Reading tags and attributes in the same way as the HTML parser of browsers, so that every attribute is checked
889
890
  * - Escaping dangerous characters in HTML attribute values
@@ -892,6 +893,7 @@ export declare interface ComposerOptions<Schema extends {
892
893
  * - Neutralizing `<base>`, `<script>` and `<plaintext>` elements, and SVG `<animate>` and `<set>` elements
893
894
  * - Disabling javascript: URLs in href (and xlink:href of SVG), src, action, formaction, and style attributes
894
895
  * - Escaping `<` in the content of `<textarea>`, `<title>`, `<style>`, `<iframe>` and similar elements
896
+ * - Following elements as browsers do, closing those still open at the end and removing end tags that close nothing
895
897
  * - Turning a tag, a comment, or an element like `<textarea>` that is not closed at the end into text
896
898
  *
897
899
  * This is useful when translation output is used in `v-html` and the translation resource contains html markup (e.g. <b> around a user provided value).
@@ -2809,6 +2811,7 @@ export declare interface VueI18nOptions<Schema extends {
2809
2811
  * Whether to escape parameters for list or named interpolation values.
2810
2812
  * When enabled, this option:
2811
2813
  * - Escapes HTML special characters (`<`, `>`, `"`, `'`, `&`, `/`, `=`) in interpolation parameters
2814
+ * - Escapes the text of interpolation parameters that are not strings, such as arrays and objects
2812
2815
  * - Sanitizes the final translated HTML to prevent XSS attacks by:
2813
2816
  * - Reading tags and attributes in the same way as the HTML parser of browsers, so that every attribute is checked
2814
2817
  * - Escaping dangerous characters in HTML attribute values
@@ -2817,6 +2820,7 @@ export declare interface VueI18nOptions<Schema extends {
2817
2820
  * - Neutralizing `<base>`, `<script>` and `<plaintext>` elements, and SVG `<animate>` and `<set>` elements
2818
2821
  * - Disabling javascript: URLs in href (and xlink:href of SVG), src, action, formaction, and style attributes
2819
2822
  * - Escaping `<` in the content of `<textarea>`, `<title>`, `<style>`, `<iframe>` and similar elements
2823
+ * - Following elements as browsers do, closing those still open at the end and removing end tags that close nothing
2820
2824
  * - Turning a tag, a comment, or an element like `<textarea>` that is not closed at the end into text
2821
2825
  *
2822
2826
  * This is useful when translation output is used in `v-html` and the translation resource contains html markup (e.g. <b> around a user provided value).
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * vue-i18n v11.4.20
2
+ * vue-i18n v11.4.22
3
3
  * (c) 2026 kazuya kawaguchi
4
4
  * Released under the MIT License.
5
5
  */
@@ -321,6 +321,169 @@ function serializeAttribute(attrName, value, quote, neutralized) {
321
321
  const valueQuote = quote || '';
322
322
  return `${name}=${valueQuote}${sanitizeAttributeValue(attrName, value)}${valueQuote}`;
323
323
  }
324
+ const HTML = 0;
325
+ const SVG = 1;
326
+ const MATHML = 2;
327
+ // Elements that have no end tag, and elements that the HTML parser does not open in the body
328
+ const notOpenedElementPattern = /^(?:area|base|basefont|bgsound|br|col|embed|frame|hr|image|img|input|keygen|link|meta|param|source|track|wbr|html|head|body|frameset)$/;
329
+ // Start tags that end SVG and MathML content (and `<font>` with `color`, `face` or `size`)
330
+ const breakoutElementPattern = /^(?:b|big|blockquote|body|br|center|code|dd|div|dl|dt|em|embed|h[1-6]|head|hr|i|img|li|listing|menu|meta|nobr|ol|p|pre|ruby|s|small|span|strong|strike|sub|sup|table|tt|u|ul|var)$/;
331
+ // Start tags that close an open `<p>`, and the elements that they do not close a `<p>` through
332
+ const paragraphClosingElementPattern = /^(?:address|article|aside|blockquote|center|details|dialog|dir|div|dl|fieldset|figcaption|figure|footer|header|hgroup|main|menu|nav|ol|p|search|section|summary|ul|h[1-6]|pre|listing|form|li|dd|dt|plaintext|table|hr|xmp)$/;
333
+ const buttonScopeElementPattern = /^(?:applet|caption|html|table|td|th|marquee|object|template|button)$/;
334
+ const svgIntegrationPattern = /^(?:foreignobject|desc|title)$/;
335
+ // The names of SVG and MathML integration points (except `title`, whose content is text in HTML). Read with the
336
+ // HTML rules, they are unknown HTML elements, and their start tags become text: if the browser closed such an
337
+ // element early (for example, `<button>` of the translation closes the `<button>` that the translation is
338
+ // rendered in), its end tag would close an integration point of the page, and the rest of the page would be read
339
+ // as SVG or MathML
340
+ const integrationNamePattern = /^(?:foreignobject|desc|mi|mo|mn|ms|mtext|annotation-xml)$/;
341
+ const mathmlIntegrationPattern = /^(?:mi|mo|mn|ms|mtext)$/;
342
+ const htmlEncodingPattern = /^(?:text\/html|application\/xhtml\+xml)$/i;
343
+ function asciiLowercase(text) {
344
+ return text.replace(/[A-Z]+/g, upper => upper.toLowerCase());
345
+ }
346
+ // Whether a start tag is read with the rules of SVG and MathML content, rather than with the HTML rules
347
+ function isForeignContext(top, name) {
348
+ return (!!top &&
349
+ top.namespace !== HTML &&
350
+ (!top.integration ||
351
+ (mathmlIntegrationPattern.test(top.name) &&
352
+ (name === 'mglyph' || name === 'malignmark'))) &&
353
+ !(top.name === 'annotation-xml' && name === 'svg'));
354
+ }
355
+ function isBreakout(name, attributes) {
356
+ return (breakoutElementPattern.test(name) ||
357
+ (name === 'font' &&
358
+ (attributes.has('color') ||
359
+ attributes.has('face') ||
360
+ attributes.has('size'))));
361
+ }
362
+ // Pop the elements down to `length`, and return their end tags (innermost first).
363
+ // A `<form>` becomes text instead: in a form of the page, browsers ignore the `<form>`,
364
+ // and `</form>` would close the form of the page
365
+ function closeDownTo(stack, length, parts) {
366
+ let endTags = '';
367
+ for (let index = stack.length - 1; index >= length; index--) {
368
+ const element = stack[index];
369
+ if (element.namespace === HTML && element.name === 'form') {
370
+ parts[element.part] = escapeLessThan(parts[element.part]);
371
+ }
372
+ else {
373
+ endTags += `</${element.name}>`;
374
+ }
375
+ }
376
+ stack.length = length;
377
+ return endTags;
378
+ }
379
+ // Pop SVG and MathML elements down to an HTML element or an integration point, as the tree builder does,
380
+ // and return their end tags
381
+ function closeForeign(stack, parts) {
382
+ let length = stack.length;
383
+ while (length > 0 &&
384
+ stack[length - 1].namespace !== HTML &&
385
+ !stack[length - 1].integration) {
386
+ length--;
387
+ }
388
+ return closeDownTo(stack, length, parts);
389
+ }
390
+ /**
391
+ * Open an element for a start tag, as the tree builder does
392
+ *
393
+ * @returns The end tags to write before the start tag: the SVG and MathML elements that it ends, and a `<p>`
394
+ * of the translation that it closes, with the elements in the `<p>` (so that no formatting element in it is
395
+ * made again after it), or `undefined` when the start tag becomes text
396
+ */
397
+ function openElement(stack, parts, name, attributes, selfClosing) {
398
+ // the start tag is written after the end tags
399
+ const part = parts.length + 1;
400
+ let endTags = '';
401
+ const top = stack[stack.length - 1];
402
+ if (isForeignContext(top, name)) {
403
+ if (!isBreakout(name, attributes)) {
404
+ if (!selfClosing) {
405
+ stack.push({
406
+ name,
407
+ namespace: top.namespace,
408
+ integration: top.namespace === SVG
409
+ ? svgIntegrationPattern.test(name)
410
+ : mathmlIntegrationPattern.test(name) ||
411
+ (name === 'annotation-xml' &&
412
+ htmlEncodingPattern.test((attributes.get('encoding') || '').replace(numericCharacterReferencePattern, decodeNumericCharacterReference))),
413
+ part
414
+ });
415
+ }
416
+ return endTags;
417
+ }
418
+ endTags = closeForeign(stack, parts);
419
+ }
420
+ if (paragraphClosingElementPattern.test(name)) {
421
+ for (let index = stack.length - 1; index >= 0; index--) {
422
+ const element = stack[index];
423
+ if (element.namespace === HTML
424
+ ? buttonScopeElementPattern.test(element.name)
425
+ : element.integration) {
426
+ break;
427
+ }
428
+ if (element.namespace === HTML && element.name === 'p') {
429
+ endTags += closeDownTo(stack, index, parts);
430
+ break;
431
+ }
432
+ }
433
+ }
434
+ if (integrationNamePattern.test(name)) {
435
+ return;
436
+ }
437
+ if (name === 'svg' || name === 'math') {
438
+ if (!selfClosing) {
439
+ stack.push({
440
+ name,
441
+ namespace: name === 'svg' ? SVG : MATHML,
442
+ integration: false,
443
+ part
444
+ });
445
+ }
446
+ }
447
+ else if (!notOpenedElementPattern.test(name)) {
448
+ // HTML elements ignore `/>`
449
+ stack.push({ name, namespace: HTML, integration: false, part });
450
+ }
451
+ return endTags;
452
+ }
453
+ /**
454
+ * Close the element of an end tag: an SVG or MathML element with the same name above the innermost HTML
455
+ * element, or else an HTML element with the same name
456
+ *
457
+ * @returns The end tags to write before the end tag (of the elements in the closed element), or `undefined`
458
+ * when the end tag closes nothing in the translation, and is removed
459
+ */
460
+ function closeElement(stack, parts, name) {
461
+ let endTags = '';
462
+ if (name === 'p' || name === 'br') {
463
+ // they end SVG and MathML content
464
+ endTags = closeForeign(stack, parts);
465
+ }
466
+ let index = stack.length - 1;
467
+ while (index >= 0 &&
468
+ stack[index].namespace !== HTML &&
469
+ stack[index].name !== name) {
470
+ index--;
471
+ }
472
+ if (index >= 0 && stack[index].namespace !== HTML) ;
473
+ else {
474
+ while (index >= 0 &&
475
+ !(stack[index].namespace === HTML && stack[index].name === name)) {
476
+ index--;
477
+ }
478
+ }
479
+ if (index < 0) {
480
+ // browsers read `</br>` as `<br>`, and `</p>` without an open `<p>` as `<p></p>`
481
+ return name === 'br' || name === 'p' ? endTags : undefined;
482
+ }
483
+ endTags += closeDownTo(stack, index + 1, parts);
484
+ stack.length = index;
485
+ return endTags;
486
+ }
324
487
  /**
325
488
  * Read a tag with the rules of the HTML tokenizer.
326
489
  * A start tag is written again with its attributes sanitized, and an end tag is kept as it is
@@ -328,7 +491,8 @@ function serializeAttribute(attrName, value, quote, neutralized) {
328
491
  * @param html - The HTML
329
492
  * @param start - The index of `<`
330
493
  * @param neutralized - What has been neutralized
331
- * @returns The tag, the tag name, and the index after the tag (-1 when the tag is not closed),
494
+ * @returns The tag, the tag name, the index after the tag (-1 when the tag is not closed),
495
+ * whether the start tag is self-closing (`/>`), and the attributes of the start tag,
332
496
  * or `undefined` when `<` does not start a tag
333
497
  */
334
498
  function readTag(html, start, neutralized) {
@@ -339,6 +503,7 @@ function readTag(html, start, neutralized) {
339
503
  }
340
504
  const [, slash, tagName] = tagStart;
341
505
  let tag = tagStart[0];
506
+ const attributes = new Map();
342
507
  let step;
343
508
  tagStepPattern.lastIndex = tagStartPattern.lastIndex;
344
509
  while ((step = tagStepPattern.exec(html))) {
@@ -346,17 +511,27 @@ function readTag(html, start, neutralized) {
346
511
  if (close) {
347
512
  const end = tagStepPattern.lastIndex;
348
513
  // browsers ignore the attributes of end tags
349
- return [slash ? html.slice(start, end) : tag + raw, tagName, end];
514
+ return [
515
+ slash ? html.slice(start, end) : tag + raw,
516
+ tagName,
517
+ end,
518
+ !slash && separator.endsWith('/'),
519
+ attributes
520
+ ];
350
521
  }
351
522
  if (quote && !closingQuote) {
352
523
  break;
353
524
  }
354
525
  if (!slash) {
355
526
  const value = quote ? quotedValue : unquotedValue;
527
+ const name = asciiLowercase(attrName);
528
+ if (!attributes.has(name)) {
529
+ attributes.set(name, value || '');
530
+ }
356
531
  tag += separator + serializeAttribute(attrName, value, quote, neutralized);
357
532
  }
358
533
  }
359
- return [tag, tagName, -1];
534
+ return [tag, tagName, -1, false, attributes];
360
535
  }
361
536
  /**
362
537
  * Find the end tag of an element whose content is text, as the HTML tokenizer does:
@@ -381,57 +556,79 @@ function findTextContentEnd(html, from, tagName) {
381
556
  * where each tag and each attribute starts and ends, and every attribute of every start tag is checked.
382
557
  * What is still open at the end of the string (a tag, a comment, or an element whose content is text,
383
558
  * like `<textarea>`) becomes text: on the server (SSR), the rest of the page follows the translation,
384
- * and it would be read as a part of what is open
559
+ * and it would be read as a part of what is open.
560
+ * For the same reason, the elements are followed as the tree builder of browsers opens and closes them,
561
+ * including SVG and MathML: an end tag that closes no element of the translation is removed, the elements
562
+ * in the element that an end tag closes are closed before it, and the elements still open at the end are
563
+ * closed. A `<form>` that the translation does not close becomes text, because browsers ignore it in a form
564
+ * of the page, and `</form>` would close that form
385
565
  *
386
566
  * @param html - The translated HTML
387
567
  * @returns The sanitized HTML
388
568
  */
389
569
  function sanitizeTranslatedHtml(html) {
390
570
  const neutralized = {};
391
- let result = '';
571
+ const parts = [];
572
+ const stack = [];
392
573
  let index = 0;
393
574
  let lessThan;
394
575
  while ((lessThan = html.indexOf('<', index)) !== -1) {
395
- result += html.slice(index, lessThan);
576
+ parts.push(html.slice(index, lessThan));
396
577
  index = lessThan + 1;
397
578
  const read = readTag(html, lessThan, neutralized);
398
579
  if (read) {
399
- const [tag, tagName, end] = read;
580
+ const [tag, tagName, end, selfClosing, attributes] = read;
400
581
  if (end === -1) {
401
582
  neutralized.unclosed = true;
402
- result += escapeLessThan(html.slice(lessThan));
583
+ parts.push(escapeLessThan(html.slice(lessThan)));
403
584
  index = html.length;
404
585
  break;
405
586
  }
406
587
  index = end;
407
588
  if (tag[1] === '/') {
408
- result += tag;
589
+ const endTags = closeElement(stack, parts, asciiLowercase(tagName));
590
+ if (endTags === undefined) {
591
+ neutralized.closed = true;
592
+ }
593
+ else {
594
+ if (endTags) {
595
+ neutralized.closed = true;
596
+ }
597
+ parts.push(endTags + tag);
598
+ }
409
599
  }
410
600
  else if (dangerousElementPattern.test(tagName)) {
411
601
  // the start tag becomes text
412
602
  neutralized.element = true;
413
- result += escapeLessThan(tag);
414
- }
415
- else if (textContentElementPattern.test(tagName)) {
416
- const contentEnd = findTextContentEnd(html, end, tagName);
417
- if (contentEnd === -1) {
418
- // the start tag becomes text, and the content is read as HTML, as browsers do then
419
- neutralized.unclosed = true;
420
- result += escapeLessThan(tag);
603
+ parts.push(escapeLessThan(tag));
604
+ }
605
+ else {
606
+ let content = '';
607
+ if (textContentElementPattern.test(tagName)) {
608
+ const contentEnd = findTextContentEnd(html, end, tagName);
609
+ if (contentEnd === -1) {
610
+ // the start tag becomes text, and the content is read as HTML, as browsers do then
611
+ neutralized.unclosed = true;
612
+ parts.push(escapeLessThan(tag));
613
+ continue;
614
+ }
615
+ content = escapeLessThan(html.slice(end, contentEnd));
616
+ index = contentEnd;
617
+ }
618
+ const endTags = openElement(stack, parts, asciiLowercase(tagName), attributes, selfClosing);
619
+ if (endTags === undefined) {
620
+ neutralized.closed = true;
621
+ parts.push(escapeLessThan(tag) + content);
421
622
  }
422
623
  else {
423
- result += tag + escapeLessThan(html.slice(end, contentEnd));
424
- index = contentEnd;
624
+ parts.push(endTags, tag + content);
425
625
  }
426
626
  }
427
- else {
428
- result += tag;
429
- }
430
627
  continue;
431
628
  }
432
629
  commentPattern.lastIndex = lessThan;
433
630
  if (commentPattern.test(html)) {
434
- result += html.slice(lessThan, commentPattern.lastIndex);
631
+ parts.push(html.slice(lessThan, commentPattern.lastIndex));
435
632
  index = commentPattern.lastIndex;
436
633
  continue;
437
634
  }
@@ -439,9 +636,21 @@ function sanitizeTranslatedHtml(html) {
439
636
  neutralized.unclosed = true;
440
637
  }
441
638
  // `<!DOCTYPE`, `<![CDATA[`, `<?`, `</` without a tag name, `<` at the end and any other `<` become text
442
- result += '&lt;';
639
+ parts.push('&lt;');
640
+ }
641
+ parts.push(html.slice(index));
642
+ // close the elements that are still open
643
+ for (let open = stack.length - 1; open >= 0; open--) {
644
+ const element = stack[open];
645
+ neutralized.closed = true;
646
+ if (element.namespace === HTML && element.name === 'form') {
647
+ // the browser ignores `<form>` in a form of the page, and `</form>` would close that form
648
+ parts[element.part] = escapeLessThan(parts[element.part]);
649
+ }
650
+ else {
651
+ parts.push(`</${element.name}>`);
652
+ }
443
653
  }
444
- result += html.slice(index);
445
654
  {
446
655
  if (neutralized.eventHandler) {
447
656
  warn('Potentially dangerous event handlers detected in translation. ' +
@@ -459,8 +668,12 @@ function sanitizeTranslatedHtml(html) {
459
668
  warn('Unclosed tag, comment or element (such as <textarea>) detected in translation. ' +
460
669
  'Consider closing it in your translation messages.');
461
670
  }
671
+ if (neutralized.closed) {
672
+ warn('Unclosed or misnested elements detected in translation. ' +
673
+ 'Consider closing every element in the right order in your translation messages.');
674
+ }
462
675
  }
463
- return result;
676
+ return parts.join('');
464
677
  }
465
678
 
466
679
  /**
@@ -2837,7 +3050,7 @@ function getWarnMessage$1(code, ...args) {
2837
3050
  * Intlify core-base version
2838
3051
  * @internal
2839
3052
  */
2840
- const VERSION$1 = '11.4.20';
3053
+ const VERSION$1 = '11.4.22';
2841
3054
  const NOT_REOSLVED = -1;
2842
3055
  const DEFAULT_LOCALE = 'en-US';
2843
3056
  const MISSING_RESOLVE_VALUE = '';
@@ -3613,7 +3826,7 @@ function translate(context, ...args) {
3613
3826
  return format;
3614
3827
  }
3615
3828
  // evaluate message with context
3616
- const ctxOptions = getMessageContextOptions(context, targetLocale, message, options);
3829
+ const ctxOptions = getMessageContextOptions(context, targetLocale, message, options, escapeParameter);
3617
3830
  const msgContext = createMessageContext(ctxOptions);
3618
3831
  const messaged = evaluateMessage(context, msg, msgContext);
3619
3832
  // if use post translation option, proceed it with handler
@@ -3649,6 +3862,8 @@ function translate(context, ...args) {
3649
3862
  }
3650
3863
  return ret;
3651
3864
  }
3865
+ // values that are not strings, such as arrays and objects, are kept here,
3866
+ // and their text is escaped when they are interpolated (see `resolveProcessor()`)
3652
3867
  function escapeParams(options) {
3653
3868
  // a call can pass both list and named values, so escape each of them
3654
3869
  if (isArray(options.list)) {
@@ -3665,6 +3880,20 @@ function escapeParams(options) {
3665
3880
  options.named = named;
3666
3881
  }
3667
3882
  }
3883
+ // strings have been escaped by `escapeParams()`. other values are turned into text here,
3884
+ // with `JSON.stringify()` for arrays and plain objects and `String()` for the rest, so escape that text
3885
+ function interpolateEscaped(value) {
3886
+ return isString(value) ? value : escapeHtml(toDisplayString(value));
3887
+ }
3888
+ function resolveProcessor(processor, escapeParameter) {
3889
+ // keep a processor that interpolates values by itself, such as the one of `<i18n-t>`, which renders VNodes
3890
+ if (!escapeParameter || isFunction(processor?.interpolate)) {
3891
+ return processor;
3892
+ }
3893
+ return assign({}, processor, {
3894
+ interpolate: interpolateEscaped
3895
+ });
3896
+ }
3668
3897
  function resolveMessageFormat(context, key, locale, fallbackLocale, fallbackWarn, missingWarn) {
3669
3898
  const { messages, onWarn, messageResolver: resolveValue, localeFallbacker } = context;
3670
3899
  const locales = localeFallbacker(context, fallbackLocale, locale); // eslint-disable-line @typescript-eslint/no-explicit-any
@@ -3904,7 +4133,7 @@ function getSourceForCodeFrame(source) {
3904
4133
  }
3905
4134
  }
3906
4135
  }
3907
- function getMessageContextOptions(context, locale, message, options) {
4136
+ function getMessageContextOptions(context, locale, message, options, escapeParameter) {
3908
4137
  const { modifiers, pluralRules, messageResolver: resolveValue, fallbackLocale, fallbackWarn, missingWarn, fallbackContext } = context;
3909
4138
  const resolveMessage = (key, useLinked) => {
3910
4139
  let val = resolveValue(message, key);
@@ -3938,8 +4167,9 @@ function getMessageContextOptions(context, locale, message, options) {
3938
4167
  pluralRules,
3939
4168
  messages: resolveMessage
3940
4169
  };
3941
- if (context.processor) {
3942
- ctxOptions.processor = context.processor;
4170
+ const processor = resolveProcessor(context.processor, escapeParameter);
4171
+ if (processor) {
4172
+ ctxOptions.processor = processor;
3943
4173
  }
3944
4174
  if (options.list) {
3945
4175
  ctxOptions.list = options.list;
@@ -3961,7 +4191,7 @@ function getMessageContextOptions(context, locale, message, options) {
3961
4191
  *
3962
4192
  * @VueI18nGeneral
3963
4193
  */
3964
- const VERSION = '11.4.20';
4194
+ const VERSION = '11.4.22';
3965
4195
  /**
3966
4196
  * This is only called development env
3967
4197
  * istanbul-ignore-next