From 4a497ecf0d07e86f0a83bd110b29a88b876940b3 Mon Sep 17 00:00:00 2001 From: Eyas Sharaiha Date: Mon, 20 Jul 2020 14:32:35 -0400 Subject: [PATCH 1/2] Support using ', - })).toMatchInlineSnapshot(` +test("escapes JSON-LD-illegal chars", () => { + expect( + helmetJsonLdProp({ + "@context": "https://schema.org", + "@type": "Person", + name: "Foo", + }) + ).toMatchInlineSnapshot(` Object { "innerHTML": "{\\"@context\\":\\"https://schema.org\\",\\"@type\\":\\"Person\\",\\"name\\":\\"Foo</script>\\"}", "type": "application/ld+json", } `); + + expect( + jsonLdScriptProps({ + "@context": "https://schema.org", + "@type": "Person", + name: "Foo", + }) + ).toMatchInlineSnapshot(` + Object { + "dangerouslySetInnerHTML": Object { + "__html": "{\\"@context\\":\\"https://schema.org\\",\\"@type\\":\\"Person\\",\\"name\\":\\"Foo</script>\\"}", + }, + "type": "application/ld+json", + } + `); }); -test('escapes JSON-LD-illegal chars', () => { - expect(helmetJsonLdProp( - { - '@context': 'https://schema.org', - '@type': 'Person', - name: ['Foo', null!, undefined!], - knows: [], - knowsAbout: { - '@type': 'CreativeWork', - name: 'Foo', - copyrightYear: 2020, - }, - }, - {space: 2})) - .toMatchInlineSnapshot(` +test("escapes JSON-LD-illegal chars", () => { + expect( + helmetJsonLdProp( + { + "@context": "https://schema.org", + "@type": "Person", + name: ["Foo", null!, undefined!], + knows: [], + knowsAbout: { + "@type": "CreativeWork", + name: "Foo", + copyrightYear: 2020, + }, + }, + { space: 2 } + ) + ).toMatchInlineSnapshot(` Object { "innerHTML": "{ \\"@context\\": \\"https://schema.org\\", @@ -61,4 +133,42 @@ test('escapes JSON-LD-illegal chars', () => { "type": "application/ld+json", } `); + + expect( + jsonLdScriptProps( + { + "@context": "https://schema.org", + "@type": "Person", + name: ["Foo", null!, undefined!], + knows: [], + knowsAbout: { + "@type": "CreativeWork", + name: "Foo", + copyrightYear: 2020, + }, + }, + { space: 2 } + ) + ).toMatchInlineSnapshot(` + Object { + "dangerouslySetInnerHTML": Object { + "__html": "{ + \\"@context\\": \\"https://schema.org\\", + \\"@type\\": \\"Person\\", + \\"name\\": [ + \\"Foo</script>\\", + null, + null + ], + \\"knows\\": [], + \\"knowsAbout\\": { + \\"@type\\": \\"CreativeWork\\", + \\"name\\": \\"Foo\\", + \\"copyrightYear\\": 2020 + } + }", + }, + "type": "application/ld+json", + } + `); });