@intlify/core 12.0.0-alpha.12 → 12.0.0-alpha.14
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/core.esm-browser.js +165 -28
- package/dist/core.esm-browser.prod.js +444 -359
- package/dist/core.global.js +165 -28
- package/dist/core.global.prod.js +498 -437
- package/dist/core.js +1 -1
- package/dist/core.node.js +1 -1
- package/dist/core.runtime.esm-browser.js +165 -28
- package/dist/core.runtime.esm-browser.prod.js +356 -271
- package/dist/core.runtime.global.js +165 -28
- package/dist/core.runtime.global.prod.js +384 -324
- package/dist/core.runtime.js +1 -1
- package/dist/core.runtime.node.js +1 -1
- package/package.json +3 -3
package/dist/core.js
CHANGED
package/dist/core.node.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @intlify/core v12.0.0-alpha.
|
|
2
|
+
* @intlify/core v12.0.0-alpha.14
|
|
3
3
|
* (c) 2016-present kazuya kawaguchi and contributors
|
|
4
4
|
* @license MIT
|
|
5
5
|
**/
|
|
@@ -221,6 +221,106 @@ function serializeAttribute(attrName, value, quote, neutralized) {
|
|
|
221
221
|
const valueQuote = quote || "";
|
|
222
222
|
return `${name}=${valueQuote}${sanitizeAttributeValue(attrName, value)}${valueQuote}`;
|
|
223
223
|
}
|
|
224
|
+
const HTML = 0;
|
|
225
|
+
const SVG = 1;
|
|
226
|
+
const MATHML = 2;
|
|
227
|
+
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)$/;
|
|
228
|
+
const breakoutElementPattern = /^(?:[bipsu]|big|blockquote|body|br|center|code|dd|div|dl|dt|em|embed|h[1-6]|head|hr|img|li|listing|menu|meta|nobr|ol|pre|ruby|small|span|strong|strike|sub|sup|table|tt|ul|var)$/;
|
|
229
|
+
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)$/;
|
|
230
|
+
const buttonScopeElementPattern = /^(?:applet|caption|html|table|td|th|marquee|object|template|button)$/;
|
|
231
|
+
const svgIntegrationPattern = /^(?:foreignobject|desc|title)$/;
|
|
232
|
+
const integrationNamePattern = /^(?:foreignobject|desc|mi|mo|mn|ms|mtext|annotation-xml)$/;
|
|
233
|
+
const mathmlIntegrationPattern = /^(?:mi|mo|mn|ms|mtext)$/;
|
|
234
|
+
const htmlEncodingPattern = /^(?:text\/html|application\/xhtml\+xml)$/i;
|
|
235
|
+
function asciiLowercase(text) {
|
|
236
|
+
return text.replace(/[A-Z]+/g, (upper) => upper.toLowerCase());
|
|
237
|
+
}
|
|
238
|
+
function isForeignContext(top, name) {
|
|
239
|
+
return !!top && top.namespace !== HTML && (!top.integration || mathmlIntegrationPattern.test(top.name) && (name === "mglyph" || name === "malignmark")) && !(top.name === "annotation-xml" && name === "svg");
|
|
240
|
+
}
|
|
241
|
+
function isBreakout(name, attributes) {
|
|
242
|
+
return breakoutElementPattern.test(name) || name === "font" && (attributes.has("color") || attributes.has("face") || attributes.has("size"));
|
|
243
|
+
}
|
|
244
|
+
function closeDownTo(stack, length, parts) {
|
|
245
|
+
let endTags = "";
|
|
246
|
+
for (let index = stack.length - 1; index >= length; index--) {
|
|
247
|
+
const element = stack[index];
|
|
248
|
+
if (element.namespace === HTML && element.name === "form") parts[element.part] = escapeLessThan(parts[element.part]);
|
|
249
|
+
else endTags += `</${element.name}>`;
|
|
250
|
+
}
|
|
251
|
+
stack.length = length;
|
|
252
|
+
return endTags;
|
|
253
|
+
}
|
|
254
|
+
function closeForeign(stack, parts) {
|
|
255
|
+
let length = stack.length;
|
|
256
|
+
while (length > 0 && stack[length - 1].namespace !== HTML && !stack[length - 1].integration) length--;
|
|
257
|
+
return closeDownTo(stack, length, parts);
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Open an element for a start tag, as the tree builder does
|
|
261
|
+
*
|
|
262
|
+
* @returns The end tags to write before the start tag: the SVG and MathML elements that it ends, and a `<p>`
|
|
263
|
+
* of the translation that it closes, with the elements in the `<p>` (so that no formatting element in it is
|
|
264
|
+
* made again after it), or `undefined` when the start tag becomes text
|
|
265
|
+
*/
|
|
266
|
+
function openElement(stack, parts, name, attributes, selfClosing) {
|
|
267
|
+
const part = parts.length + 1;
|
|
268
|
+
let endTags = "";
|
|
269
|
+
const top = stack[stack.length - 1];
|
|
270
|
+
if (isForeignContext(top, name)) {
|
|
271
|
+
if (!isBreakout(name, attributes)) {
|
|
272
|
+
if (!selfClosing) stack.push({
|
|
273
|
+
name,
|
|
274
|
+
namespace: top.namespace,
|
|
275
|
+
integration: top.namespace === SVG ? svgIntegrationPattern.test(name) : mathmlIntegrationPattern.test(name) || name === "annotation-xml" && htmlEncodingPattern.test((attributes.get("encoding") || "").replace(numericCharacterReferencePattern, decodeNumericCharacterReference)),
|
|
276
|
+
part
|
|
277
|
+
});
|
|
278
|
+
return endTags;
|
|
279
|
+
}
|
|
280
|
+
endTags = closeForeign(stack, parts);
|
|
281
|
+
}
|
|
282
|
+
if (paragraphClosingElementPattern.test(name)) for (let index = stack.length - 1; index >= 0; index--) {
|
|
283
|
+
const element = stack[index];
|
|
284
|
+
if (element.namespace === HTML ? buttonScopeElementPattern.test(element.name) : element.integration) break;
|
|
285
|
+
if (element.namespace === HTML && element.name === "p") {
|
|
286
|
+
endTags += closeDownTo(stack, index, parts);
|
|
287
|
+
break;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
if (integrationNamePattern.test(name)) return;
|
|
291
|
+
if (name === "svg" || name === "math") {
|
|
292
|
+
if (!selfClosing) stack.push({
|
|
293
|
+
name,
|
|
294
|
+
namespace: name === "svg" ? SVG : MATHML,
|
|
295
|
+
integration: false,
|
|
296
|
+
part
|
|
297
|
+
});
|
|
298
|
+
} else if (!notOpenedElementPattern.test(name)) stack.push({
|
|
299
|
+
name,
|
|
300
|
+
namespace: HTML,
|
|
301
|
+
integration: false,
|
|
302
|
+
part
|
|
303
|
+
});
|
|
304
|
+
return endTags;
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Close the element of an end tag: an SVG or MathML element with the same name above the innermost HTML
|
|
308
|
+
* element, or else an HTML element with the same name
|
|
309
|
+
*
|
|
310
|
+
* @returns The end tags to write before the end tag (of the elements in the closed element), or `undefined`
|
|
311
|
+
* when the end tag closes nothing in the translation, and is removed
|
|
312
|
+
*/
|
|
313
|
+
function closeElement(stack, parts, name) {
|
|
314
|
+
let endTags = "";
|
|
315
|
+
if (name === "p" || name === "br") endTags = closeForeign(stack, parts);
|
|
316
|
+
let index = stack.length - 1;
|
|
317
|
+
while (index >= 0 && stack[index].namespace !== HTML && stack[index].name !== name) index--;
|
|
318
|
+
if (index >= 0 && stack[index].namespace !== HTML) {} else while (index >= 0 && !(stack[index].namespace === HTML && stack[index].name === name)) index--;
|
|
319
|
+
if (index < 0) return name === "br" || name === "p" ? endTags : void 0;
|
|
320
|
+
endTags += closeDownTo(stack, index + 1, parts);
|
|
321
|
+
stack.length = index;
|
|
322
|
+
return endTags;
|
|
323
|
+
}
|
|
224
324
|
/**
|
|
225
325
|
* Read a tag with the rules of the HTML tokenizer.
|
|
226
326
|
* A start tag is written again with its attributes sanitized, and an end tag is kept as it is
|
|
@@ -228,7 +328,8 @@ function serializeAttribute(attrName, value, quote, neutralized) {
|
|
|
228
328
|
* @param html - The HTML
|
|
229
329
|
* @param start - The index of `<`
|
|
230
330
|
* @param neutralized - What has been neutralized
|
|
231
|
-
* @returns The tag, the tag name,
|
|
331
|
+
* @returns The tag, the tag name, the index after the tag (-1 when the tag is not closed),
|
|
332
|
+
* whether the start tag is self-closing (`/>`), and the attributes of the start tag,
|
|
232
333
|
* or `undefined` when `<` does not start a tag
|
|
233
334
|
*/
|
|
234
335
|
function readTag(html, start, neutralized) {
|
|
@@ -237,6 +338,7 @@ function readTag(html, start, neutralized) {
|
|
|
237
338
|
if (!tagStart) return;
|
|
238
339
|
const [, slash, tagName] = tagStart;
|
|
239
340
|
let tag = tagStart[0];
|
|
341
|
+
const attributes = /* @__PURE__ */ new Map();
|
|
240
342
|
let step;
|
|
241
343
|
tagStepPattern.lastIndex = tagStartPattern.lastIndex;
|
|
242
344
|
while (step = tagStepPattern.exec(html)) {
|
|
@@ -246,16 +348,25 @@ function readTag(html, start, neutralized) {
|
|
|
246
348
|
return [
|
|
247
349
|
slash ? html.slice(start, end) : tag + raw,
|
|
248
350
|
tagName,
|
|
249
|
-
end
|
|
351
|
+
end,
|
|
352
|
+
!slash && separator.endsWith("/"),
|
|
353
|
+
attributes
|
|
250
354
|
];
|
|
251
355
|
}
|
|
252
356
|
if (quote && !closingQuote) break;
|
|
253
|
-
if (!slash)
|
|
357
|
+
if (!slash) {
|
|
358
|
+
const value = quote ? quotedValue : unquotedValue;
|
|
359
|
+
const name = asciiLowercase(attrName);
|
|
360
|
+
if (!attributes.has(name)) attributes.set(name, value || "");
|
|
361
|
+
tag += separator + serializeAttribute(attrName, value, quote, neutralized);
|
|
362
|
+
}
|
|
254
363
|
}
|
|
255
364
|
return [
|
|
256
365
|
tag,
|
|
257
366
|
tagName,
|
|
258
|
-
-1
|
|
367
|
+
-1,
|
|
368
|
+
false,
|
|
369
|
+
attributes
|
|
259
370
|
];
|
|
260
371
|
}
|
|
261
372
|
/**
|
|
@@ -279,60 +390,87 @@ function findTextContentEnd(html, from, tagName) {
|
|
|
279
390
|
* where each tag and each attribute starts and ends, and every attribute of every start tag is checked.
|
|
280
391
|
* What is still open at the end of the string (a tag, a comment, or an element whose content is text,
|
|
281
392
|
* like `<textarea>`) becomes text: on the server (SSR), the rest of the page follows the translation,
|
|
282
|
-
* and it would be read as a part of what is open
|
|
393
|
+
* and it would be read as a part of what is open.
|
|
394
|
+
* For the same reason, the elements are followed as the tree builder of browsers opens and closes them,
|
|
395
|
+
* including SVG and MathML: an end tag that closes no element of the translation is removed, the elements
|
|
396
|
+
* in the element that an end tag closes are closed before it, and the elements still open at the end are
|
|
397
|
+
* closed. A `<form>` that the translation does not close becomes text, because browsers ignore it in a form
|
|
398
|
+
* of the page, and `</form>` would close that form
|
|
283
399
|
*
|
|
284
400
|
* @param html - The translated HTML
|
|
285
401
|
* @returns The sanitized HTML
|
|
286
402
|
*/
|
|
287
403
|
function sanitizeTranslatedHtml(html) {
|
|
288
404
|
const neutralized = {};
|
|
289
|
-
|
|
405
|
+
const parts = [];
|
|
406
|
+
const stack = [];
|
|
290
407
|
let index = 0;
|
|
291
408
|
let lessThan;
|
|
292
409
|
while ((lessThan = html.indexOf("<", index)) !== -1) {
|
|
293
|
-
|
|
410
|
+
parts.push(html.slice(index, lessThan));
|
|
294
411
|
index = lessThan + 1;
|
|
295
412
|
const read = readTag(html, lessThan, neutralized);
|
|
296
413
|
if (read) {
|
|
297
|
-
const [tag, tagName, end] = read;
|
|
414
|
+
const [tag, tagName, end, selfClosing, attributes] = read;
|
|
298
415
|
if (end === -1) {
|
|
299
416
|
neutralized.unclosed = true;
|
|
300
|
-
|
|
417
|
+
parts.push(escapeLessThan(html.slice(lessThan)));
|
|
301
418
|
index = html.length;
|
|
302
419
|
break;
|
|
303
420
|
}
|
|
304
421
|
index = end;
|
|
305
|
-
if (tag[1] === "/")
|
|
306
|
-
|
|
422
|
+
if (tag[1] === "/") {
|
|
423
|
+
const endTags = closeElement(stack, parts, asciiLowercase(tagName));
|
|
424
|
+
if (endTags === void 0) neutralized.closed = true;
|
|
425
|
+
else {
|
|
426
|
+
if (endTags) neutralized.closed = true;
|
|
427
|
+
parts.push(endTags + tag);
|
|
428
|
+
}
|
|
429
|
+
} else if (dangerousElementPattern.test(tagName)) {
|
|
307
430
|
neutralized.element = true;
|
|
308
|
-
|
|
309
|
-
} else
|
|
310
|
-
|
|
311
|
-
if (
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
431
|
+
parts.push(escapeLessThan(tag));
|
|
432
|
+
} else {
|
|
433
|
+
let content = "";
|
|
434
|
+
if (textContentElementPattern.test(tagName)) {
|
|
435
|
+
const contentEnd = findTextContentEnd(html, end, tagName);
|
|
436
|
+
if (contentEnd === -1) {
|
|
437
|
+
neutralized.unclosed = true;
|
|
438
|
+
parts.push(escapeLessThan(tag));
|
|
439
|
+
continue;
|
|
440
|
+
}
|
|
441
|
+
content = escapeLessThan(html.slice(end, contentEnd));
|
|
316
442
|
index = contentEnd;
|
|
317
443
|
}
|
|
318
|
-
|
|
444
|
+
const endTags = openElement(stack, parts, asciiLowercase(tagName), attributes, selfClosing);
|
|
445
|
+
if (endTags === void 0) {
|
|
446
|
+
neutralized.closed = true;
|
|
447
|
+
parts.push(escapeLessThan(tag) + content);
|
|
448
|
+
} else parts.push(endTags, tag + content);
|
|
449
|
+
}
|
|
319
450
|
continue;
|
|
320
451
|
}
|
|
321
452
|
commentPattern.lastIndex = lessThan;
|
|
322
453
|
if (commentPattern.test(html)) {
|
|
323
|
-
|
|
454
|
+
parts.push(html.slice(lessThan, commentPattern.lastIndex));
|
|
324
455
|
index = commentPattern.lastIndex;
|
|
325
456
|
continue;
|
|
326
457
|
}
|
|
327
458
|
if (html.startsWith("<!--", lessThan)) neutralized.unclosed = true;
|
|
328
|
-
|
|
459
|
+
parts.push("<");
|
|
460
|
+
}
|
|
461
|
+
parts.push(html.slice(index));
|
|
462
|
+
for (let open = stack.length - 1; open >= 0; open--) {
|
|
463
|
+
const element = stack[open];
|
|
464
|
+
neutralized.closed = true;
|
|
465
|
+
if (element.namespace === HTML && element.name === "form") parts[element.part] = escapeLessThan(parts[element.part]);
|
|
466
|
+
else parts.push(`</${element.name}>`);
|
|
329
467
|
}
|
|
330
|
-
result += html.slice(index);
|
|
331
468
|
if (neutralized.eventHandler) warn("Potentially dangerous event handlers detected in translation. Consider removing onclick, onerror, etc. from your translation messages.");
|
|
332
469
|
if (neutralized.srcdoc) warn("Potentially dangerous srcdoc attribute detected in translation. Consider removing srcdoc from your translation messages.");
|
|
333
470
|
if (neutralized.element) warn("Potentially dangerous element (<base>, <animate>, <set>, <script> or <plaintext>) detected in translation. Consider removing it from your translation messages.");
|
|
334
471
|
if (neutralized.unclosed) warn("Unclosed tag, comment or element (such as <textarea>) detected in translation. Consider closing it in your translation messages.");
|
|
335
|
-
|
|
472
|
+
if (neutralized.closed) warn("Unclosed or misnested elements detected in translation. Consider closing every element in the right order in your translation messages.");
|
|
473
|
+
return parts.join("");
|
|
336
474
|
}
|
|
337
475
|
// packages/shared/src/messages.ts
|
|
338
476
|
const isNotObjectOrIsArray = (val) => !isObject(val) || isArray(val);
|
|
@@ -891,8 +1029,7 @@ function resolveValue(obj, path) {
|
|
|
891
1029
|
*/
|
|
892
1030
|
if (AST_NODE_PROPS_KEYS.includes(key) && isMessageAST(last)) return null;
|
|
893
1031
|
if (!isObject(last)) return null;
|
|
894
|
-
|
|
895
|
-
const val = last[key];
|
|
1032
|
+
const val = getOwn(last, key);
|
|
896
1033
|
if (val === void 0) return null;
|
|
897
1034
|
if (isFunction(last)) return null;
|
|
898
1035
|
last = val;
|
|
@@ -939,7 +1076,7 @@ function getWarnMessage(code, ...args) {
|
|
|
939
1076
|
* Intlify core-base version
|
|
940
1077
|
* @internal
|
|
941
1078
|
*/
|
|
942
|
-
const VERSION = "12.0.0-alpha.
|
|
1079
|
+
const VERSION = "12.0.0-alpha.14";
|
|
943
1080
|
const NOT_RESOLVED = -1;
|
|
944
1081
|
const DEFAULT_LOCALE = "en-US";
|
|
945
1082
|
const MISSING_RESOLVE_VALUE = "";
|