Skip to content

Commit

Permalink
fix: convert space to commas in sandbox attr
Browse files Browse the repository at this point in the history
The `sandbox` attribute on an `<iframe>` element will be space-
delimited, but our convention is to have this be comma-delimited
on the IframeEmbed annotation
  • Loading branch information
bachbui committed Nov 1, 2023
1 parent ba0fd9e commit f424b10
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
19 changes: 11 additions & 8 deletions packages/@atjson/source-html/src/converter/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Document, { Annotation } from "@atjson/document";
import Document, { Annotation, AttributesOf } from "@atjson/document";
import OffsetSource, {
CodeBlock,
List,
Expand Down Expand Up @@ -44,18 +44,21 @@ HTMLSource.defineConverterTo(OffsetSource, function HTMLToOffset(doc) {
convertVideoEmbeds(doc);

doc.where({ type: "-html-iframe" }).update(function updateIframes(iframe) {
const attributes = {
url: iframe.attributes.src,
height: iframe.attributes.height,
width: iframe.attributes.width,
anchorName: iframe.attributes.id,
} as AttributesOf<IframeEmbed>;
if (iframe.attributes.sandbox) {
attributes.sandbox = iframe.attributes.sandbox.split(" ").join(",");
}
doc.replaceAnnotation(
iframe,
new IframeEmbed({
start: iframe.start,
end: iframe.end,
attributes: {
url: iframe.attributes.src,
height: iframe.attributes.height,
width: iframe.attributes.width,
sandbox: iframe.attributes.sandbox,
anchorName: iframe.attributes.id,
},
attributes,
})
);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/@atjson/source-html/test/converter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ describe("@atjson/source-html", () => {
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>`
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(`
Expand Down

0 comments on commit f424b10

Please sign in to comment.