~james/core

core/web/src/lib/seo/jsonLd.test.ts -rw-r--r-- 633 bytes
452f17b7 — james chore(import): snapshot james.dad.town/core at f70c71c7696a 16 hours ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import { describe, expect, it } from "vitest";
import { serializeJsonLd } from "#lib/seo/jsonLd.ts";

describe("serializeJsonLd", () => {
	it("cannot close the surrounding script tag", () => {
		const out = serializeJsonLd({ description: "</script><script>alert(1)</script>" });
		expect(out).not.toMatch(/[<>]/);
		expect(out).toContain("\\u003c/script\\u003e");
	});

	it("round-trips to the same value", () => {
		const schema = { name: "a & b", description: "x < y > z \u2028 \u2029 <!--" };
		const out = serializeJsonLd(schema);
		expect(out).not.toMatch(/[&\u2028\u2029]/);
		expect(JSON.parse(out)).toEqual(schema);
	});
});