From 16fd18373672604128992ab7fd6899972a8c1aa4 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 4 Nov 2026 08:43:08 +0000 Subject: [PATCH] Escape <, >, &, U+2028 and U+2029 in the JSON-LD script JsonLd.astro wrote JSON.stringify(data) raw into ended the element early and put the rest of the JSON into the page as HTML, and > done', + description: 'Line\u2028and paragraph\u2029separators', + keywords: ['', 'a&b'], + }; + const json = serializeJsonLd(data); + // With no `<` left, the browser can't find `&\u2028\u2029]/); + assert.match(json, /"Ends early \\u003c\/script\\u003e\\u003cb\\u003ex\\u003c\/b\\u003e \\u0026 \\u003c!-- comment/); + assert.match(json, /"Line\\u2028and paragraph\\u2029separators"/); + assert.deepEqual(JSON.parse(json), data); +}); + +test('JSON-LD without those characters is plain JSON.stringify', () => { + const data = { '@context': 'https://schema.org', name: 'meaningfool', sameAs: ['https://github.com/meaningfool'] }; + assert.equal(serializeJsonLd(data), JSON.stringify(data)); +});