vue-i18n 11.4.21 → 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.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * vue-i18n v11.4.21
2
+ * vue-i18n v11.4.22
3
3
  * (c) 2026 kazuya kawaguchi
4
4
  * Released under the MIT License.
5
5
  */
@@ -334,6 +334,169 @@ var VueI18n = (function (exports, Vue) {
334
334
  const valueQuote = quote || '';
335
335
  return `${name}=${valueQuote}${sanitizeAttributeValue(attrName, value)}${valueQuote}`;
336
336
  }
337
+ const HTML = 0;
338
+ const SVG = 1;
339
+ const MATHML = 2;
340
+ // Elements that have no end tag, and elements that the HTML parser does not open in the body
341
+ 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)$/;
342
+ // Start tags that end SVG and MathML content (and `<font>` with `color`, `face` or `size`)
343
+ 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)$/;
344
+ // Start tags that close an open `<p>`, and the elements that they do not close a `<p>` through
345
+ 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)$/;
346
+ const buttonScopeElementPattern = /^(?:applet|caption|html|table|td|th|marquee|object|template|button)$/;
347
+ const svgIntegrationPattern = /^(?:foreignobject|desc|title)$/;
348
+ // The names of SVG and MathML integration points (except `title`, whose content is text in HTML). Read with the
349
+ // HTML rules, they are unknown HTML elements, and their start tags become text: if the browser closed such an
350
+ // element early (for example, `<button>` of the translation closes the `<button>` that the translation is
351
+ // rendered in), its end tag would close an integration point of the page, and the rest of the page would be read
352
+ // as SVG or MathML
353
+ const integrationNamePattern = /^(?:foreignobject|desc|mi|mo|mn|ms|mtext|annotation-xml)$/;
354
+ const mathmlIntegrationPattern = /^(?:mi|mo|mn|ms|mtext)$/;
355
+ const htmlEncodingPattern = /^(?:text\/html|application\/xhtml\+xml)$/i;
356
+ function asciiLowercase(text) {
357
+ return text.replace(/[A-Z]+/g, upper => upper.toLowerCase());
358
+ }
359
+ // Whether a start tag is read with the rules of SVG and MathML content, rather than with the HTML rules
360
+ function isForeignContext(top, name) {
361
+ return (!!top &&
362
+ top.namespace !== HTML &&
363
+ (!top.integration ||
364
+ (mathmlIntegrationPattern.test(top.name) &&
365
+ (name === 'mglyph' || name === 'malignmark'))) &&
366
+ !(top.name === 'annotation-xml' && name === 'svg'));
367
+ }
368
+ function isBreakout(name, attributes) {
369
+ return (breakoutElementPattern.test(name) ||
370
+ (name === 'font' &&
371
+ (attributes.has('color') ||
372
+ attributes.has('face') ||
373
+ attributes.has('size'))));
374
+ }
375
+ // Pop the elements down to `length`, and return their end tags (innermost first).
376
+ // A `<form>` becomes text instead: in a form of the page, browsers ignore the `<form>`,
377
+ // and `</form>` would close the form of the page
378
+ function closeDownTo(stack, length, parts) {
379
+ let endTags = '';
380
+ for (let index = stack.length - 1; index >= length; index--) {
381
+ const element = stack[index];
382
+ if (element.namespace === HTML && element.name === 'form') {
383
+ parts[element.part] = escapeLessThan(parts[element.part]);
384
+ }
385
+ else {
386
+ endTags += `</${element.name}>`;
387
+ }
388
+ }
389
+ stack.length = length;
390
+ return endTags;
391
+ }
392
+ // Pop SVG and MathML elements down to an HTML element or an integration point, as the tree builder does,
393
+ // and return their end tags
394
+ function closeForeign(stack, parts) {
395
+ let length = stack.length;
396
+ while (length > 0 &&
397
+ stack[length - 1].namespace !== HTML &&
398
+ !stack[length - 1].integration) {
399
+ length--;
400
+ }
401
+ return closeDownTo(stack, length, parts);
402
+ }
403
+ /**
404
+ * Open an element for a start tag, as the tree builder does
405
+ *
406
+ * @returns The end tags to write before the start tag: the SVG and MathML elements that it ends, and a `<p>`
407
+ * of the translation that it closes, with the elements in the `<p>` (so that no formatting element in it is
408
+ * made again after it), or `undefined` when the start tag becomes text
409
+ */
410
+ function openElement(stack, parts, name, attributes, selfClosing) {
411
+ // the start tag is written after the end tags
412
+ const part = parts.length + 1;
413
+ let endTags = '';
414
+ const top = stack[stack.length - 1];
415
+ if (isForeignContext(top, name)) {
416
+ if (!isBreakout(name, attributes)) {
417
+ if (!selfClosing) {
418
+ stack.push({
419
+ name,
420
+ namespace: top.namespace,
421
+ integration: top.namespace === SVG
422
+ ? svgIntegrationPattern.test(name)
423
+ : mathmlIntegrationPattern.test(name) ||
424
+ (name === 'annotation-xml' &&
425
+ htmlEncodingPattern.test((attributes.get('encoding') || '').replace(numericCharacterReferencePattern, decodeNumericCharacterReference))),
426
+ part
427
+ });
428
+ }
429
+ return endTags;
430
+ }
431
+ endTags = closeForeign(stack, parts);
432
+ }
433
+ if (paragraphClosingElementPattern.test(name)) {
434
+ for (let index = stack.length - 1; index >= 0; index--) {
435
+ const element = stack[index];
436
+ if (element.namespace === HTML
437
+ ? buttonScopeElementPattern.test(element.name)
438
+ : element.integration) {
439
+ break;
440
+ }
441
+ if (element.namespace === HTML && element.name === 'p') {
442
+ endTags += closeDownTo(stack, index, parts);
443
+ break;
444
+ }
445
+ }
446
+ }
447
+ if (integrationNamePattern.test(name)) {
448
+ return;
449
+ }
450
+ if (name === 'svg' || name === 'math') {
451
+ if (!selfClosing) {
452
+ stack.push({
453
+ name,
454
+ namespace: name === 'svg' ? SVG : MATHML,
455
+ integration: false,
456
+ part
457
+ });
458
+ }
459
+ }
460
+ else if (!notOpenedElementPattern.test(name)) {
461
+ // HTML elements ignore `/>`
462
+ stack.push({ name, namespace: HTML, integration: false, part });
463
+ }
464
+ return endTags;
465
+ }
466
+ /**
467
+ * Close the element of an end tag: an SVG or MathML element with the same name above the innermost HTML
468
+ * element, or else an HTML element with the same name
469
+ *
470
+ * @returns The end tags to write before the end tag (of the elements in the closed element), or `undefined`
471
+ * when the end tag closes nothing in the translation, and is removed
472
+ */
473
+ function closeElement(stack, parts, name) {
474
+ let endTags = '';
475
+ if (name === 'p' || name === 'br') {
476
+ // they end SVG and MathML content
477
+ endTags = closeForeign(stack, parts);
478
+ }
479
+ let index = stack.length - 1;
480
+ while (index >= 0 &&
481
+ stack[index].namespace !== HTML &&
482
+ stack[index].name !== name) {
483
+ index--;
484
+ }
485
+ if (index >= 0 && stack[index].namespace !== HTML) ;
486
+ else {
487
+ while (index >= 0 &&
488
+ !(stack[index].namespace === HTML && stack[index].name === name)) {
489
+ index--;
490
+ }
491
+ }
492
+ if (index < 0) {
493
+ // browsers read `</br>` as `<br>`, and `</p>` without an open `<p>` as `<p></p>`
494
+ return name === 'br' || name === 'p' ? endTags : undefined;
495
+ }
496
+ endTags += closeDownTo(stack, index + 1, parts);
497
+ stack.length = index;
498
+ return endTags;
499
+ }
337
500
  /**
338
501
  * Read a tag with the rules of the HTML tokenizer.
339
502
  * A start tag is written again with its attributes sanitized, and an end tag is kept as it is
@@ -341,7 +504,8 @@ var VueI18n = (function (exports, Vue) {
341
504
  * @param html - The HTML
342
505
  * @param start - The index of `<`
343
506
  * @param neutralized - What has been neutralized
344
- * @returns The tag, the tag name, and the index after the tag (-1 when the tag is not closed),
507
+ * @returns The tag, the tag name, the index after the tag (-1 when the tag is not closed),
508
+ * whether the start tag is self-closing (`/>`), and the attributes of the start tag,
345
509
  * or `undefined` when `<` does not start a tag
346
510
  */
347
511
  function readTag(html, start, neutralized) {
@@ -352,6 +516,7 @@ var VueI18n = (function (exports, Vue) {
352
516
  }
353
517
  const [, slash, tagName] = tagStart;
354
518
  let tag = tagStart[0];
519
+ const attributes = new Map();
355
520
  let step;
356
521
  tagStepPattern.lastIndex = tagStartPattern.lastIndex;
357
522
  while ((step = tagStepPattern.exec(html))) {
@@ -359,17 +524,27 @@ var VueI18n = (function (exports, Vue) {
359
524
  if (close) {
360
525
  const end = tagStepPattern.lastIndex;
361
526
  // browsers ignore the attributes of end tags
362
- return [slash ? html.slice(start, end) : tag + raw, tagName, end];
527
+ return [
528
+ slash ? html.slice(start, end) : tag + raw,
529
+ tagName,
530
+ end,
531
+ !slash && separator.endsWith('/'),
532
+ attributes
533
+ ];
363
534
  }
364
535
  if (quote && !closingQuote) {
365
536
  break;
366
537
  }
367
538
  if (!slash) {
368
539
  const value = quote ? quotedValue : unquotedValue;
540
+ const name = asciiLowercase(attrName);
541
+ if (!attributes.has(name)) {
542
+ attributes.set(name, value || '');
543
+ }
369
544
  tag += separator + serializeAttribute(attrName, value, quote, neutralized);
370
545
  }
371
546
  }
372
- return [tag, tagName, -1];
547
+ return [tag, tagName, -1, false, attributes];
373
548
  }
374
549
  /**
375
550
  * Find the end tag of an element whose content is text, as the HTML tokenizer does:
@@ -394,57 +569,79 @@ var VueI18n = (function (exports, Vue) {
394
569
  * where each tag and each attribute starts and ends, and every attribute of every start tag is checked.
395
570
  * What is still open at the end of the string (a tag, a comment, or an element whose content is text,
396
571
  * like `<textarea>`) becomes text: on the server (SSR), the rest of the page follows the translation,
397
- * and it would be read as a part of what is open
572
+ * and it would be read as a part of what is open.
573
+ * For the same reason, the elements are followed as the tree builder of browsers opens and closes them,
574
+ * including SVG and MathML: an end tag that closes no element of the translation is removed, the elements
575
+ * in the element that an end tag closes are closed before it, and the elements still open at the end are
576
+ * closed. A `<form>` that the translation does not close becomes text, because browsers ignore it in a form
577
+ * of the page, and `</form>` would close that form
398
578
  *
399
579
  * @param html - The translated HTML
400
580
  * @returns The sanitized HTML
401
581
  */
402
582
  function sanitizeTranslatedHtml(html) {
403
583
  const neutralized = {};
404
- let result = '';
584
+ const parts = [];
585
+ const stack = [];
405
586
  let index = 0;
406
587
  let lessThan;
407
588
  while ((lessThan = html.indexOf('<', index)) !== -1) {
408
- result += html.slice(index, lessThan);
589
+ parts.push(html.slice(index, lessThan));
409
590
  index = lessThan + 1;
410
591
  const read = readTag(html, lessThan, neutralized);
411
592
  if (read) {
412
- const [tag, tagName, end] = read;
593
+ const [tag, tagName, end, selfClosing, attributes] = read;
413
594
  if (end === -1) {
414
595
  neutralized.unclosed = true;
415
- result += escapeLessThan(html.slice(lessThan));
596
+ parts.push(escapeLessThan(html.slice(lessThan)));
416
597
  index = html.length;
417
598
  break;
418
599
  }
419
600
  index = end;
420
601
  if (tag[1] === '/') {
421
- result += tag;
602
+ const endTags = closeElement(stack, parts, asciiLowercase(tagName));
603
+ if (endTags === undefined) {
604
+ neutralized.closed = true;
605
+ }
606
+ else {
607
+ if (endTags) {
608
+ neutralized.closed = true;
609
+ }
610
+ parts.push(endTags + tag);
611
+ }
422
612
  }
423
613
  else if (dangerousElementPattern.test(tagName)) {
424
614
  // the start tag becomes text
425
615
  neutralized.element = true;
426
- result += escapeLessThan(tag);
427
- }
428
- else if (textContentElementPattern.test(tagName)) {
429
- const contentEnd = findTextContentEnd(html, end, tagName);
430
- if (contentEnd === -1) {
431
- // the start tag becomes text, and the content is read as HTML, as browsers do then
432
- neutralized.unclosed = true;
433
- result += escapeLessThan(tag);
616
+ parts.push(escapeLessThan(tag));
617
+ }
618
+ else {
619
+ let content = '';
620
+ if (textContentElementPattern.test(tagName)) {
621
+ const contentEnd = findTextContentEnd(html, end, tagName);
622
+ if (contentEnd === -1) {
623
+ // the start tag becomes text, and the content is read as HTML, as browsers do then
624
+ neutralized.unclosed = true;
625
+ parts.push(escapeLessThan(tag));
626
+ continue;
627
+ }
628
+ content = escapeLessThan(html.slice(end, contentEnd));
629
+ index = contentEnd;
630
+ }
631
+ const endTags = openElement(stack, parts, asciiLowercase(tagName), attributes, selfClosing);
632
+ if (endTags === undefined) {
633
+ neutralized.closed = true;
634
+ parts.push(escapeLessThan(tag) + content);
434
635
  }
435
636
  else {
436
- result += tag + escapeLessThan(html.slice(end, contentEnd));
437
- index = contentEnd;
637
+ parts.push(endTags, tag + content);
438
638
  }
439
639
  }
440
- else {
441
- result += tag;
442
- }
443
640
  continue;
444
641
  }
445
642
  commentPattern.lastIndex = lessThan;
446
643
  if (commentPattern.test(html)) {
447
- result += html.slice(lessThan, commentPattern.lastIndex);
644
+ parts.push(html.slice(lessThan, commentPattern.lastIndex));
448
645
  index = commentPattern.lastIndex;
449
646
  continue;
450
647
  }
@@ -452,9 +649,21 @@ var VueI18n = (function (exports, Vue) {
452
649
  neutralized.unclosed = true;
453
650
  }
454
651
  // `<!DOCTYPE`, `<![CDATA[`, `<?`, `</` without a tag name, `<` at the end and any other `<` become text
455
- result += '&lt;';
652
+ parts.push('&lt;');
653
+ }
654
+ parts.push(html.slice(index));
655
+ // close the elements that are still open
656
+ for (let open = stack.length - 1; open >= 0; open--) {
657
+ const element = stack[open];
658
+ neutralized.closed = true;
659
+ if (element.namespace === HTML && element.name === 'form') {
660
+ // the browser ignores `<form>` in a form of the page, and `</form>` would close that form
661
+ parts[element.part] = escapeLessThan(parts[element.part]);
662
+ }
663
+ else {
664
+ parts.push(`</${element.name}>`);
665
+ }
456
666
  }
457
- result += html.slice(index);
458
667
  {
459
668
  if (neutralized.eventHandler) {
460
669
  warn('Potentially dangerous event handlers detected in translation. ' +
@@ -472,8 +681,12 @@ var VueI18n = (function (exports, Vue) {
472
681
  warn('Unclosed tag, comment or element (such as <textarea>) detected in translation. ' +
473
682
  'Consider closing it in your translation messages.');
474
683
  }
684
+ if (neutralized.closed) {
685
+ warn('Unclosed or misnested elements detected in translation. ' +
686
+ 'Consider closing every element in the right order in your translation messages.');
687
+ }
475
688
  }
476
- return result;
689
+ return parts.join('');
477
690
  }
478
691
 
479
692
  /**
@@ -2850,7 +3063,7 @@ var VueI18n = (function (exports, Vue) {
2850
3063
  * Intlify core-base version
2851
3064
  * @internal
2852
3065
  */
2853
- const VERSION$1 = '11.4.21';
3066
+ const VERSION$1 = '11.4.22';
2854
3067
  const NOT_REOSLVED = -1;
2855
3068
  const DEFAULT_LOCALE = 'en-US';
2856
3069
  const MISSING_RESOLVE_VALUE = '';
@@ -3988,7 +4201,7 @@ var VueI18n = (function (exports, Vue) {
3988
4201
  *
3989
4202
  * @VueI18nGeneral
3990
4203
  */
3991
- const VERSION = '11.4.21';
4204
+ const VERSION = '11.4.22';
3992
4205
  /**
3993
4206
  * This is only called development env
3994
4207
  * istanbul-ignore-next