Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import { classifyMarkdownImageSource } from "./markdownImages.js";
4
5describe("classifyMarkdownImageSource", () => {
6 it.each([
7 ["images/result.png", "/workspace/project", "/workspace/project/images/result.png"],
8 // A backslash is an ordinary filename character on POSIX, not a separator.
9 ["./a%5Cb.png", "/workspace/project", "/workspace/project/./a\\b.png"],
10 [
11 "images\\result.png",
12 "C:\\Users\\dara\\project",
13 "C:\\Users\\dara\\project\\images\\result.png",
14 ],
15 ["file:///workspace/project/image%20one.png", null, "/workspace/project/image one.png"],
16 ["file://server/share/image.png", "\\\\server\\share", "\\\\server\\share\\image.png"],
17 ])("maps %s to a workspace file", (source, workspaceRoot, path) => {
18 expect(classifyMarkdownImageSource(source, workspaceRoot)).toEqual({
19 _tag: "WorkspaceFile",
20 path,
21 ...(source.startsWith("file:") ? {} : { relative: true }),
22 });
23 });
24
25 it.each(["image.png", "javascript:alert(1)", "file://%"])(
26 "blocks unsupported or unresolved source %s",
27 (source) => {
28 expect(classifyMarkdownImageSource(source)).toEqual({ _tag: "Blocked" });
29 },
30 );
31
32 // Loading these makes Windows send the user's NTLM credentials to the named host.
33 it.each([
34 "file://attacker.test/share/cat.jpg",
35 "\\\\attacker.test\\share\\cat.jpg",
36 "/\\attacker.test\\share\\cat.jpg",
37 "file:/%5Cattacker.test%5Cshare%5Ccat.jpg",
38 "\\\\server\\other\\cat.jpg",
39 ])("blocks network path %s outside the project", (source) => {
40 expect(classifyMarkdownImageSource(source, "\\\\server\\share\\project")).toEqual({
41 _tag: "Blocked",
42 });
43 });
44});