vue-i18n 11.4.17 → 11.4.19

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.17
2
+ * vue-i18n v11.4.19
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.17';
33
+ const VERSION = '11.4.19';
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>` 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>` 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.17
2
+ * vue-i18n v11.4.19
3
3
  * (c) 2026 kazuya kawaguchi
4
4
  * Released under the MIT License.
5
5
  */
@@ -209,17 +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
- // can set `href` of an SVG `<a>` through `values` or `to`, which the URL check does not look at
220
- const dangerousElementPattern = /<(?:base|animate|set)(?=[\s/>]|$)/i;
221
- const dangerousElementStartTagPattern = /<(base|animate|set)(?=[\s/>]|$)/gi;
222
- const unquotedUrlAttributePattern = /(^|[\s"'<>/])((?:href|xlink:href|src|action|formaction)\s*=\s*)([^\s"'=<>`]+)/gi;
217
+ // can set `href` of an SVG `<a>` through `values` or `to`, which the URL check does not look at.
218
+ // `<script>` does not run when inserted with `innerHTML`, but it runs when the HTML is rendered
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;
223
232
  function decodeNumericCharacterReference(match, hex, decimal) {
224
233
  const digits = hex || decimal;
225
234
  if (!digits) {
@@ -291,42 +300,167 @@ function sanitizeAttributeValue(attrName, value) {
291
300
  const sanitizedValue = attrName.toLowerCase() === 'style' ? sanitizeStyleValue(value) : value;
292
301
  return escapeAttributeValue(sanitizedValue);
293
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
+ */
294
389
  function sanitizeTranslatedHtml(html) {
295
- // Escape dangerous characters in attribute values
296
- // Process attributes with double quotes
297
- html = html.replace(/([\w:-]+)\s*=\s*"([^"]*)"/g, (_, attrName, attrValue) => `${attrName}="${sanitizeAttributeValue(attrName, attrValue)}"`);
298
- // Process attributes with single quotes
299
- html = html.replace(/([\w:-]+)\s*=\s*'([^']*)'/g, (_, attrName, attrValue) => `${attrName}='${sanitizeAttributeValue(attrName, attrValue)}'`);
300
- // Detect and neutralize event handler attributes
301
- if (eventHandlerPattern.test(html)) {
302
- {
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) {
303
447
  warn('Potentially dangerous event handlers detected in translation. ' +
304
448
  'Consider removing onclick, onerror, etc. from your translation messages.');
305
449
  }
306
- // Neutralize event handler attributes by escaping 'on'
307
- html = html.replace(eventHandlerAttributePattern, '$1&#111;n$2');
308
- }
309
- // Detect and neutralize `srcdoc` attributes
310
- if (srcdocPattern.test(html)) {
311
- {
450
+ if (neutralized.srcdoc) {
312
451
  warn('Potentially dangerous srcdoc attribute detected in translation. ' +
313
452
  'Consider removing srcdoc from your translation messages.');
314
453
  }
315
- // Neutralize `srcdoc` by escaping 's': character references are not decoded in attribute names
316
- html = html.replace(srcdocAttributePattern, '$1&#115;$2');
317
- }
318
- // Detect and neutralize `<base>`, `<animate>` and `<set>` elements
319
- if (dangerousElementPattern.test(html)) {
320
- {
321
- warn('Potentially dangerous element (<base>, <animate> or <set>) detected in translation. ' +
322
- 'Consider removing it from your translation messages.');
454
+ if (neutralized.element) {
455
+ warn('Potentially dangerous element (<base>, <animate>, <set>, <script> or <plaintext>) ' +
456
+ 'detected in translation. Consider removing it from your translation messages.');
457
+ }
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.');
323
461
  }
324
- // Neutralize these elements by escaping '<': the start tag becomes text
325
- html = html.replace(dangerousElementStartTagPattern, '&lt;$1');
326
462
  }
327
- // Disable javascript: URLs in unquoted attributes
328
- html = html.replace(unquotedUrlAttributePattern, (match, boundary, prefix, attrValue) => hasJavascriptScheme(attrValue) ? `${boundary}${prefix}about:blank` : match);
329
- return html;
463
+ return result;
330
464
  }
331
465
 
332
466
  /**
@@ -2705,7 +2839,7 @@ function getWarnMessage$1(code, ...args) {
2705
2839
  * Intlify core-base version
2706
2840
  * @internal
2707
2841
  */
2708
- const VERSION$1 = '11.4.17';
2842
+ const VERSION$1 = '11.4.19';
2709
2843
  const NOT_REOSLVED = -1;
2710
2844
  const DEFAULT_LOCALE = 'en-US';
2711
2845
  const MISSING_RESOLVE_VALUE = '';
@@ -3829,7 +3963,7 @@ function getMessageContextOptions(context, locale, message, options) {
3829
3963
  *
3830
3964
  * @VueI18nGeneral
3831
3965
  */
3832
- const VERSION = '11.4.17';
3966
+ const VERSION = '11.4.19';
3833
3967
  /**
3834
3968
  * This is only called development env
3835
3969
  * istanbul-ignore-next