Skip to content

Commit

Permalink
chore: convert iframe sandbox attr
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bachbui committed Nov 1, 2023
1 parent e159ce7 commit 3396085
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/@atjson/source-html/src/converter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
})
Expand Down
27 changes: 27 additions & 0 deletions packages/@atjson/source-html/test/converter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,33 @@ describe("@atjson/source-html", () => {
`);
});

test("iframe embeds with sandbox", () => {
let doc = HTMLSource.fromRaw(
`<iframe src="https://example.com"
scrolling="no" frameborder="0"
allowTransparency="true" allow="encrypted-media" sandbox="allow-same-origin,allow-scripts,allow-popups,allow-popups-to-escape-sandbox,allow-forms"></iframe>`
).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(
Expand Down

0 comments on commit 3396085

Please sign in to comment.