vue-i18n 11.4.18 → 11.4.20

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.18
2
+ * vue-i18n v11.4.20
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.18';
33
+ const VERSION = '11.4.20';
34
34
 
35
35
  const I18nErrorCodes = {
36
36
  // composer module errors
@@ -885,11 +885,14 @@ export declare interface ComposerOptions<Schema extends {
885
885
  * When enabled, this option:
886
886
  * - Escapes HTML special characters (`<`, `>`, `"`, `'`, `&`, `/`, `=`) in interpolation parameters
887
887
  * - Sanitizes the final translated HTML to prevent XSS attacks by:
888
+ * - Reading tags and attributes in the same way as the HTML parser of browsers, so that every attribute is checked
888
889
  * - Escaping dangerous characters in HTML attribute values
889
890
  * - Neutralizing event handler attributes (onclick, onerror, etc.)
890
891
  * - Neutralizing the `srcdoc` attribute of `<iframe>`
891
- * - Neutralizing `<base>` and `<script>` elements, and SVG `<animate>` and `<set>` elements
892
+ * - Neutralizing `<base>`, `<script>` and `<plaintext>` elements, and SVG `<animate>` and `<set>` elements
892
893
  * - Disabling javascript: URLs in href (and xlink:href of SVG), src, action, formaction, and style attributes
894
+ * - Escaping `<` in the content of `<textarea>`, `<title>`, `<style>`, `<iframe>` and similar elements
895
+ * - Turning a tag, a comment, or an element like `<textarea>` that is not closed at the end into text
893
896
  *
894
897
  * 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).
895
898
  *
@@ -2807,11 +2810,14 @@ export declare interface VueI18nOptions<Schema extends {
2807
2810
  * When enabled, this option:
2808
2811
  * - Escapes HTML special characters (`<`, `>`, `"`, `'`, `&`, `/`, `=`) in interpolation parameters
2809
2812
  * - Sanitizes the final translated HTML to prevent XSS attacks by:
2813
+ * - Reading tags and attributes in the same way as the HTML parser of browsers, so that every attribute is checked
2810
2814
  * - Escaping dangerous characters in HTML attribute values
2811
2815
  * - Neutralizing event handler attributes (onclick, onerror, etc.)
2812
2816
  * - Neutralizing the `srcdoc` attribute of `<iframe>`
2813
- * - Neutralizing `<base>` and `<script>` elements, and SVG `<animate>` and `<set>` elements
2817
+ * - Neutralizing `<base>`, `<script>` and `<plaintext>` elements, and SVG `<animate>` and `<set>` elements
2814
2818
  * - Disabling javascript: URLs in href (and xlink:href of SVG), src, action, formaction, and style attributes
2819
+ * - Escaping `<` in the content of `<textarea>`, `<title>`, `<style>`, `<iframe>` and similar elements
2820
+ * - Turning a tag, a comment, or an element like `<textarea>` that is not closed at the end into text
2815
2821
  *
2816
2822
  * 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).
2817
2823
  *
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * vue-i18n v11.4.18
2
+ * vue-i18n v11.4.20
3
3
  * (c) 2026 kazuya kawaguchi
4
4
  * Released under the MIT License.
5
5
  */
@@ -209,19 +209,26 @@ const namedWhitespaceCharacterReferencePattern = /&(?:Tab|NewLine);/g;
209
209
  const colonCharacterReferencePattern = /&colon;?/gi;
210
210
  // eslint-disable-next-line no-control-regex -- URL scheme normalization requires the full control range
211
211
  const controlOrWhitespacePattern = /[\u0000-\u0020\u007f-\u009f]/g;
212
- const eventHandlerPattern = /(?:^|[\s"'<>/])on\w+\s*=\s*["']?[^"'>]+["']?/i;
213
- const eventHandlerAttributePattern = /(^|[\s"'<>/])on(\w+\s*=)/gi;
212
+ const eventHandlerPattern = /^on\w/i;
214
213
  // `srcdoc` holds a whole HTML document: its value is entity-decoded and then parsed again,
215
214
  // so neither escaping the value nor neutralizing `on*` inside it makes it inert
216
- const srcdocPattern = /(?:^|[\s"'<>/])srcdoc\s*=/i;
217
- const srcdocAttributePattern = /(^|[\s"'<>/])s(rcdoc\s*=)/gi;
215
+ const srcdocPattern = /^srcdoc$/i;
218
216
  // `<base>` changes how the page resolves every relative URL after it, and SVG `<animate>` and `<set>`
219
217
  // can set `href` of an SVG `<a>` through `values` or `to`, which the URL check does not look at.
220
218
  // `<script>` does not run when inserted with `innerHTML`, but it runs when the HTML is rendered
221
- // on the server (SSR) and the browser parses it as part of the page
222
- const dangerousElementPattern = /<(?:base|animate|set|script)(?=[\s/>]|$)/i;
223
- const dangerousElementStartTagPattern = /<(base|animate|set|script)(?=[\s/>]|$)/gi;
224
- const unquotedUrlAttributePattern = /(^|[\s"'<>/])((?:href|xlink:href|src|action|formaction)\s*=\s*)([^\s"'=<>`]+)/gi;
219
+ // on the server (SSR) and the browser parses it as part of the page.
220
+ // `<plaintext>` turns the rest of the page into text
221
+ const dangerousElementPattern = /^(?:base|animate|set|script|plaintext)$/i;
222
+ // The content of these elements is text up to their end tag when they are HTML elements, and markup when
223
+ // they are SVG or MathML elements. Their content is turned into text, so that it reads the same in both
224
+ const textContentElementPattern = /^(?:iframe|noembed|noframes|noscript|style|textarea|title|xmp)$/i;
225
+ // The rules of the HTML tokenizer for tags, comments, and the end of a tag that is not closed (`$`):
226
+ // - `<` or `</`, and the tag name
227
+ const tagStartPattern = /<(\/?)([a-z][^\t\n\f\r />]*)/iy;
228
+ // - whitespace and `/`, and then `>` or an attribute: its name, and its value in quotes or without quotes
229
+ const tagStepPattern = /([\t\n\f\r /]*)(?:(>)|([^\t\n\f\r />][^\t\n\f\r />=]*)(?:[\t\n\f\r ]*=[\t\n\f\r ]*(?:(["'])([\s\S]*?)(\4|$)|([^\t\n\f\r >]*)))?)/y;
230
+ // - a comment, which ends with `-->` or `--!>`, or with `>` or `->` right after `<!--`
231
+ const commentPattern = /<!--(?:>|->|[\s\S]*?--!?>)/y;
225
232
  function decodeNumericCharacterReference(match, hex, decimal) {
226
233
  const digits = hex || decimal;
227
234
  if (!digits) {
@@ -293,42 +300,167 @@ function sanitizeAttributeValue(attrName, value) {
293
300
  const sanitizedValue = attrName.toLowerCase() === 'style' ? sanitizeStyleValue(value) : value;
294
301
  return escapeAttributeValue(sanitizedValue);
295
302
  }
303
+ function escapeLessThan(text) {
304
+ return text.replace(/</g, '&lt;');
305
+ }
306
+ function serializeAttribute(attrName, value, quote, neutralized) {
307
+ // Character references are not decoded in attribute names, so escaping a character renames the attribute
308
+ let name = attrName;
309
+ if (eventHandlerPattern.test(attrName)) {
310
+ neutralized.eventHandler = true;
311
+ name = `&#111;n${attrName.slice(2)}`;
312
+ }
313
+ else if (srcdocPattern.test(attrName)) {
314
+ neutralized.srcdoc = true;
315
+ name = `&#115;${attrName.slice(1)}`;
316
+ }
317
+ if (value === undefined) {
318
+ return name;
319
+ }
320
+ // An unquoted value stays unquoted: it has no whitespace or `>`, and escaping does not add them
321
+ const valueQuote = quote || '';
322
+ return `${name}=${valueQuote}${sanitizeAttributeValue(attrName, value)}${valueQuote}`;
323
+ }
324
+ /**
325
+ * Read a tag with the rules of the HTML tokenizer.
326
+ * A start tag is written again with its attributes sanitized, and an end tag is kept as it is
327
+ *
328
+ * @param html - The HTML
329
+ * @param start - The index of `<`
330
+ * @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),
332
+ * or `undefined` when `<` does not start a tag
333
+ */
334
+ function readTag(html, start, neutralized) {
335
+ tagStartPattern.lastIndex = start;
336
+ const tagStart = tagStartPattern.exec(html);
337
+ if (!tagStart) {
338
+ return;
339
+ }
340
+ const [, slash, tagName] = tagStart;
341
+ let tag = tagStart[0];
342
+ let step;
343
+ tagStepPattern.lastIndex = tagStartPattern.lastIndex;
344
+ while ((step = tagStepPattern.exec(html))) {
345
+ const [raw, separator, close, attrName, quote, quotedValue, closingQuote, unquotedValue] = step;
346
+ if (close) {
347
+ const end = tagStepPattern.lastIndex;
348
+ // browsers ignore the attributes of end tags
349
+ return [slash ? html.slice(start, end) : tag + raw, tagName, end];
350
+ }
351
+ if (quote && !closingQuote) {
352
+ break;
353
+ }
354
+ if (!slash) {
355
+ const value = quote ? quotedValue : unquotedValue;
356
+ tag += separator + serializeAttribute(attrName, value, quote, neutralized);
357
+ }
358
+ }
359
+ return [tag, tagName, -1];
360
+ }
361
+ /**
362
+ * Find the end tag of an element whose content is text, as the HTML tokenizer does:
363
+ * the first `</` followed by the tag name, and by whitespace, `/` or `>`
364
+ *
365
+ * @returns The index of the end tag, or -1 when it is not found or not closed in the string
366
+ */
367
+ function findTextContentEnd(html, from, tagName) {
368
+ for (let index = html.indexOf('</', from); index !== -1; index = html.indexOf('</', index + 2)) {
369
+ const endTag = readTag(html, index, {});
370
+ if (endTag && endTag[1].toLowerCase() === tagName.toLowerCase()) {
371
+ return endTag[2] === -1 ? -1 : index;
372
+ }
373
+ }
374
+ return -1;
375
+ }
376
+ /**
377
+ * Sanitize the translated HTML
378
+ *
379
+ * @remarks
380
+ * Tags are read with the rules of the HTML tokenizer, so that the sanitizer and browsers agree on
381
+ * where each tag and each attribute starts and ends, and every attribute of every start tag is checked.
382
+ * What is still open at the end of the string (a tag, a comment, or an element whose content is text,
383
+ * 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
385
+ *
386
+ * @param html - The translated HTML
387
+ * @returns The sanitized HTML
388
+ */
296
389
  function sanitizeTranslatedHtml(html) {
297
- // Escape dangerous characters in attribute values
298
- // Process attributes with double quotes
299
- html = html.replace(/([\w:-]+)\s*=\s*"([^"]*)"/g, (_, attrName, attrValue) => `${attrName}="${sanitizeAttributeValue(attrName, attrValue)}"`);
300
- // Process attributes with single quotes
301
- html = html.replace(/([\w:-]+)\s*=\s*'([^']*)'/g, (_, attrName, attrValue) => `${attrName}='${sanitizeAttributeValue(attrName, attrValue)}'`);
302
- // Detect and neutralize event handler attributes
303
- if (eventHandlerPattern.test(html)) {
304
- {
390
+ const neutralized = {};
391
+ let result = '';
392
+ let index = 0;
393
+ let lessThan;
394
+ while ((lessThan = html.indexOf('<', index)) !== -1) {
395
+ result += html.slice(index, lessThan);
396
+ index = lessThan + 1;
397
+ const read = readTag(html, lessThan, neutralized);
398
+ if (read) {
399
+ const [tag, tagName, end] = read;
400
+ if (end === -1) {
401
+ neutralized.unclosed = true;
402
+ result += escapeLessThan(html.slice(lessThan));
403
+ index = html.length;
404
+ break;
405
+ }
406
+ index = end;
407
+ if (tag[1] === '/') {
408
+ result += tag;
409
+ }
410
+ else if (dangerousElementPattern.test(tagName)) {
411
+ // the start tag becomes text
412
+ 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);
421
+ }
422
+ else {
423
+ result += tag + escapeLessThan(html.slice(end, contentEnd));
424
+ index = contentEnd;
425
+ }
426
+ }
427
+ else {
428
+ result += tag;
429
+ }
430
+ continue;
431
+ }
432
+ commentPattern.lastIndex = lessThan;
433
+ if (commentPattern.test(html)) {
434
+ result += html.slice(lessThan, commentPattern.lastIndex);
435
+ index = commentPattern.lastIndex;
436
+ continue;
437
+ }
438
+ if (html.startsWith('<!--', lessThan)) {
439
+ neutralized.unclosed = true;
440
+ }
441
+ // `<!DOCTYPE`, `<![CDATA[`, `<?`, `</` without a tag name, `<` at the end and any other `<` become text
442
+ result += '&lt;';
443
+ }
444
+ result += html.slice(index);
445
+ {
446
+ if (neutralized.eventHandler) {
305
447
  warn('Potentially dangerous event handlers detected in translation. ' +
306
448
  'Consider removing onclick, onerror, etc. from your translation messages.');
307
449
  }
308
- // Neutralize event handler attributes by escaping 'on'
309
- html = html.replace(eventHandlerAttributePattern, '$1&#111;n$2');
310
- }
311
- // Detect and neutralize `srcdoc` attributes
312
- if (srcdocPattern.test(html)) {
313
- {
450
+ if (neutralized.srcdoc) {
314
451
  warn('Potentially dangerous srcdoc attribute detected in translation. ' +
315
452
  'Consider removing srcdoc from your translation messages.');
316
453
  }
317
- // Neutralize `srcdoc` by escaping 's': character references are not decoded in attribute names
318
- html = html.replace(srcdocAttributePattern, '$1&#115;$2');
319
- }
320
- // Detect and neutralize `<base>`, `<animate>`, `<set>` and `<script>` elements
321
- if (dangerousElementPattern.test(html)) {
322
- {
323
- warn('Potentially dangerous element (<base>, <animate>, <set> or <script>) ' +
454
+ if (neutralized.element) {
455
+ warn('Potentially dangerous element (<base>, <animate>, <set>, <script> or <plaintext>) ' +
324
456
  'detected in translation. Consider removing it from your translation messages.');
325
457
  }
326
- // Neutralize these elements by escaping '<': the start tag becomes text
327
- html = html.replace(dangerousElementStartTagPattern, '&lt;$1');
458
+ if (neutralized.unclosed) {
459
+ warn('Unclosed tag, comment or element (such as <textarea>) detected in translation. ' +
460
+ 'Consider closing it in your translation messages.');
461
+ }
328
462
  }
329
- // Disable javascript: URLs in unquoted attributes
330
- html = html.replace(unquotedUrlAttributePattern, (match, boundary, prefix, attrValue) => hasJavascriptScheme(attrValue) ? `${boundary}${prefix}about:blank` : match);
331
- return html;
463
+ return result;
332
464
  }
333
465
 
334
466
  /**
@@ -566,7 +698,7 @@ function createScanner(str) {
566
698
  }
567
699
 
568
700
  const EOF = undefined;
569
- const DOT = '.';
701
+ const TAB = '\t';
570
702
  const LITERAL_DELIMITER = "'";
571
703
  const ERROR_DOMAIN$3 = 'tokenizer';
572
704
  function createTokenizer(source, options = {}) {
@@ -1015,32 +1147,30 @@ function createTokenizer(source, options = {}) {
1015
1147
  }
1016
1148
  return name;
1017
1149
  }
1150
+ // LinkedKeyChar ::= AnyChar - LinkedKeySpecialChar (spec/syntax.ebnf)
1151
+ function isLinkedKeyChar(ch) {
1152
+ return !(ch === "{" /* TokenChars.BraceLeft */ ||
1153
+ ch === "@" /* TokenChars.LinkedAlias */ ||
1154
+ ch === "|" /* TokenChars.Pipe */ ||
1155
+ ch === "(" /* TokenChars.ParenLeft */ ||
1156
+ ch === ")" /* TokenChars.ParenRight */ ||
1157
+ ch === CHAR_SP ||
1158
+ ch === TAB ||
1159
+ ch === CHAR_LF);
1160
+ }
1018
1161
  function readLinkedRefer(scnr) {
1019
- const fn = (buf) => {
1020
- const ch = scnr.currentChar();
1021
- if (ch === "{" /* TokenChars.BraceLeft */ ||
1022
- ch === "@" /* TokenChars.LinkedAlias */ ||
1023
- ch === "|" /* TokenChars.Pipe */ ||
1024
- ch === "(" /* TokenChars.ParenLeft */ ||
1025
- ch === ")" /* TokenChars.ParenRight */ ||
1026
- !ch) {
1027
- return buf;
1028
- }
1029
- else if (ch === CHAR_SP) {
1030
- return buf;
1031
- }
1032
- else if (ch === CHAR_LF || ch === DOT) {
1033
- buf += ch;
1034
- scnr.next();
1035
- return fn(buf);
1036
- }
1037
- else {
1038
- buf += ch;
1039
- scnr.next();
1040
- return fn(buf);
1041
- }
1042
- };
1043
- return fn('');
1162
+ // A tab right after `:` has been read into the key, and the key path resolver ignores it.
1163
+ // Skip it, so that the key does not end before it starts.
1164
+ while (scnr.currentChar() === TAB) {
1165
+ scnr.next();
1166
+ }
1167
+ let buf = '';
1168
+ let ch;
1169
+ while ((ch = scnr.currentChar()) && isLinkedKeyChar(ch)) {
1170
+ buf += ch;
1171
+ scnr.next();
1172
+ }
1173
+ return buf;
1044
1174
  }
1045
1175
  function readPlural(scnr) {
1046
1176
  skipSpaces(scnr);
@@ -2707,7 +2837,7 @@ function getWarnMessage$1(code, ...args) {
2707
2837
  * Intlify core-base version
2708
2838
  * @internal
2709
2839
  */
2710
- const VERSION$1 = '11.4.18';
2840
+ const VERSION$1 = '11.4.20';
2711
2841
  const NOT_REOSLVED = -1;
2712
2842
  const DEFAULT_LOCALE = 'en-US';
2713
2843
  const MISSING_RESOLVE_VALUE = '';
@@ -3831,7 +3961,7 @@ function getMessageContextOptions(context, locale, message, options) {
3831
3961
  *
3832
3962
  * @VueI18nGeneral
3833
3963
  */
3834
- const VERSION = '11.4.18';
3964
+ const VERSION = '11.4.20';
3835
3965
  /**
3836
3966
  * This is only called development env
3837
3967
  * istanbul-ignore-next