@terpjs/react-core 0.41.1 → 0.43.0
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/package.json +5 -5
- package/src/ui/Markdown.test.tsx +14 -0
- package/src/ui/Markdown.tsx +14 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@terpjs/react-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.43.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Terp React stack core — typed @terpjs/contract client provider, auth session, capability gates, TanStack Router adapter, app shell, page archetypes, DataView and token-styled UI primitives. First frontend stack; see README.md for the component catalog.",
|
|
6
6
|
"exports": {
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@tanstack/react-router": "^1.170.46",
|
|
18
|
-
"@terpjs/contract": "^0.
|
|
18
|
+
"@terpjs/contract": "^0.43.0"
|
|
19
19
|
},
|
|
20
20
|
"peerDependencies": {
|
|
21
21
|
"react": "^19.0.0",
|
|
@@ -26,12 +26,12 @@
|
|
|
26
26
|
"@testing-library/react": "^16.3.3",
|
|
27
27
|
"@types/react": "^19.3.0",
|
|
28
28
|
"@types/react-dom": "^19.3.0",
|
|
29
|
-
"@vitejs/plugin-react": "^6.
|
|
30
|
-
"jsdom": "^31.0.
|
|
29
|
+
"@vitejs/plugin-react": "^6.3.0",
|
|
30
|
+
"jsdom": "^31.0.1",
|
|
31
31
|
"react": "^19.3.1",
|
|
32
32
|
"react-dom": "^19.3.1",
|
|
33
33
|
"typescript": "^6.0.3",
|
|
34
|
-
"vite": "^8.3.
|
|
34
|
+
"vite": "^8.3.8",
|
|
35
35
|
"vitest": "^5.1.0"
|
|
36
36
|
},
|
|
37
37
|
"license": "Apache-2.0",
|
package/src/ui/Markdown.test.tsx
CHANGED
|
@@ -20,6 +20,20 @@ describe("Markdown", () => {
|
|
|
20
20
|
expect(screen.getAllByRole("list")).toHaveLength(2);
|
|
21
21
|
});
|
|
22
22
|
|
|
23
|
+
it("preserves supported destinations and renders ambiguous destinations as text", () => {
|
|
24
|
+
const allowed = [
|
|
25
|
+
"https://example.test/path", "HTTP://example.test/", "mailto:help@example.test",
|
|
26
|
+
"../records", "#details", "?page=2",
|
|
27
|
+
];
|
|
28
|
+
const refused = ["f\ttp://example.test/", "//example.test", "\\\\example.test", "/\\example.test", "https://[", "https:records"];
|
|
29
|
+
const source = [...allowed, ...refused].map((href, i) => `[item ${i}](${href})`).join(" ");
|
|
30
|
+
render(<Markdown source={source} />);
|
|
31
|
+
expect(screen.getAllByRole("link").map((link) => link.getAttribute("href"))).toEqual(allowed);
|
|
32
|
+
for (const [index] of refused.entries()) {
|
|
33
|
+
expect(screen.getByText(`item ${index + allowed.length}`, { exact: false })).toBeInTheDocument();
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
|
|
23
37
|
it("allows only safe links and renders raw html as text", () => {
|
|
24
38
|
const { container } = render(
|
|
25
39
|
<Markdown source={'[safe](records/1) [bad](javascript:alert(1)) <img src=x onerror=alert(1)>'} />,
|
package/src/ui/Markdown.tsx
CHANGED
|
@@ -30,10 +30,22 @@ type Block =
|
|
|
30
30
|
| { type: "code"; text: string }
|
|
31
31
|
| { type: "list"; ordered: boolean; items: string[] };
|
|
32
32
|
|
|
33
|
-
const
|
|
33
|
+
const RELATIVE_LINK_BASE = "https://markdown.invalid";
|
|
34
34
|
|
|
35
35
|
function isSafeLink(href: string): boolean {
|
|
36
|
-
|
|
36
|
+
// Browsers strip ASCII controls or interpret backslashes as URL separators.
|
|
37
|
+
// Reject those spellings before resolving the same href the anchor will use.
|
|
38
|
+
if (href.startsWith("//") || href.includes("\\") || /[\u0000-\u001f\u007f]/u.test(href)) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
const url = new URL(href, RELATIVE_LINK_BASE);
|
|
43
|
+
if (/^https?:\/\//i.test(href)) return url.protocol === "https:" || url.protocol === "http:";
|
|
44
|
+
if (/^mailto:/i.test(href)) return url.protocol === "mailto:";
|
|
45
|
+
return !/^[a-z][a-z0-9+.-]*:/i.test(href) && url.origin === RELATIVE_LINK_BASE;
|
|
46
|
+
} catch {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
37
49
|
}
|
|
38
50
|
|
|
39
51
|
function parseBlocks(source: string): Block[] {
|