From 33960855c76c8006dcbf44cf90f8ce4ff76f6a4f Mon Sep 17 00:00:00 2001 From: Bach Bui Date: Wed, 1 Nov 2023 13:29:31 -0400 Subject: [PATCH] chore: convert iframe `sandbox` attr Update our html-source to convert the `sandbox` attribute for iframe elements. This attribute is already supported in the iframe-embed annotation in the offset-annotations source --- .../source-html/src/converter/index.ts | 1 + .../source-html/test/converter.test.ts | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/packages/@atjson/source-html/src/converter/index.ts b/packages/@atjson/source-html/src/converter/index.ts index b7c96cac9..67501401e 100644 --- a/packages/@atjson/source-html/src/converter/index.ts +++ b/packages/@atjson/source-html/src/converter/index.ts @@ -53,6 +53,7 @@ HTMLSource.defineConverterTo(OffsetSource, function HTMLToOffset(doc) { url: iframe.attributes.src, height: iframe.attributes.height, width: iframe.attributes.width, + sandbox: iframe.attributes.sandbox, anchorName: iframe.attributes.id, }, }) diff --git a/packages/@atjson/source-html/test/converter.test.ts b/packages/@atjson/source-html/test/converter.test.ts index b409262eb..fdc080002 100644 --- a/packages/@atjson/source-html/test/converter.test.ts +++ b/packages/@atjson/source-html/test/converter.test.ts @@ -544,6 +544,33 @@ describe("@atjson/source-html", () => { `); }); + test("iframe embeds with sandbox", () => { + let doc = HTMLSource.fromRaw( + `` + ).convertTo(OffsetSource); + + expect(serialize(doc, { withStableIds: true })).toMatchInlineSnapshot(` + { + "blocks": [ + { + "attributes": { + "sandbox": "allow-same-origin,allow-scripts,allow-popups,allow-popups-to-escape-sandbox,allow-forms", + "url": "https://example.com", + }, + "id": "B00000000", + "parents": [], + "selfClosing": false, + "type": "iframe-embed", + }, + ], + "marks": [], + "text": "", + } + `); + }); + describe("social embeds", () => { test("Facebook iframe embed", () => { let doc = HTMLSource.fromRaw(