@thexjs/core 1.2.0 → 1.2.2
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/index.js +17 -5
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -446,8 +446,12 @@ function decodeLinkUrl(url) {
|
|
|
446
446
|
return url;
|
|
447
447
|
}
|
|
448
448
|
}
|
|
449
|
+
function stripUrlControlChars(url) {
|
|
450
|
+
return url.replace(/[\t\n\r]/g, "");
|
|
451
|
+
}
|
|
449
452
|
function isSafeLinkUrl(url) {
|
|
450
|
-
const
|
|
453
|
+
const clean = stripUrlControlChars(url);
|
|
454
|
+
const scheme = LINK_SCHEME_RE.exec(decodeLinkUrl(clean.trim()))?.[1]?.toLowerCase();
|
|
451
455
|
return scheme === void 0 || ALLOWED_LINK_SCHEMES.has(scheme);
|
|
452
456
|
}
|
|
453
457
|
function renderMarkdown(md) {
|
|
@@ -460,10 +464,10 @@ function renderMarkdown(md) {
|
|
|
460
464
|
html = html.replace(/^### (.+)$/gm, "<h3>$1</h3>").replace(/^## (.+)$/gm, "<h2>$1</h2>").replace(/^# (.+)$/gm, "<h1>$1</h1>").replace(/`([^`]+)`/g, (_m, code) => {
|
|
461
465
|
inlineCodes.push(code);
|
|
462
466
|
return `__X_CODE_${inlineCodes.length - 1}__`;
|
|
463
|
-
}).replace(/\*\*([^*]+)\*\*/g, "<strong>$1</strong>").replace(/\*([^*]+)\*/g, "<em>$1</em>").replace(
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
).replace(/__X_CODE_(\d+)__/g, (_m, i) => `<code>${inlineCodes[Number.parseInt(i)]}</code>`);
|
|
467
|
+
}).replace(/\*\*([^*]+)\*\*/g, "<strong>$1</strong>").replace(/\*([^*]+)\*/g, "<em>$1</em>").replace(/\[([^\]]+)\]\(([^)]+)\)/g, (_m, text, href) => {
|
|
468
|
+
const clean = stripUrlControlChars(href);
|
|
469
|
+
return isSafeLinkUrl(clean) ? `<a href="${clean}">${text}</a>` : text;
|
|
470
|
+
}).replace(/__X_CODE_(\d+)__/g, (_m, i) => `<code>${inlineCodes[Number.parseInt(i)]}</code>`);
|
|
467
471
|
html = html.replace(/__X_FENCE_(\d+)__/g, (_m, i) => fences[Number.parseInt(i)] ?? "");
|
|
468
472
|
const blocks = html.split(/\n\n+/);
|
|
469
473
|
html = blocks.map((b) => {
|
|
@@ -1070,6 +1074,13 @@ async function buildIslandBundleInMemory(routeFilePath, layoutFilePaths, islandN
|
|
|
1070
1074
|
assertNoEnvLeakage(code, entryPath);
|
|
1071
1075
|
return wrapIslandBundle(code);
|
|
1072
1076
|
} catch (err) {
|
|
1077
|
+
if (err instanceof EnvLeakageError) {
|
|
1078
|
+
console.error(
|
|
1079
|
+
`\x1B[1;31m\u{1F512} SECURITY: [islands] ${err.message}\x1B[0m
|
|
1080
|
+
Falling back to a non-interactive hydration stub \u2014 fix the env isolation (prefix with THEXJS_PUBLIC_ or move the access server-side) before relying on this page's client behavior.`
|
|
1081
|
+
);
|
|
1082
|
+
return wrapIslandBundle(generateFallbackHydration(islandNames));
|
|
1083
|
+
}
|
|
1073
1084
|
console.warn(` [islands] build failed for ${routeFilePath}:`, err);
|
|
1074
1085
|
return wrapIslandBundle(generateFallbackHydration(islandNames));
|
|
1075
1086
|
} finally {
|
|
@@ -2349,6 +2360,7 @@ async function bundleRouteIslands(routeFilePath, layoutFilePaths, islandNames, i
|
|
|
2349
2360
|
console.warn(` [islands] build error: ${log.message}`);
|
|
2350
2361
|
}
|
|
2351
2362
|
} catch (err) {
|
|
2363
|
+
if (err instanceof EnvLeakageError) throw err;
|
|
2352
2364
|
console.warn(` [islands] build failed for ${routeFilePath}:`, err);
|
|
2353
2365
|
}
|
|
2354
2366
|
writeFileSync3(bundlePath, wrapIslandBundle(generateFallbackHydration(islandNames)), "utf-8");
|
package/package.json
CHANGED