Skip to content

Commit

Permalink
refactor: escape all attributes with default serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
lihbr committed Oct 4, 2023
1 parent 8e5da1a commit 52ad75d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/lib/serializerHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const formatAttributes = (node: RTAnyNode, attributes: Attributes): string => {
if (typeof value === "boolean") {
result.push(key);
} else {
result.push(`${key}="${value}"`);
result.push(`${key}="${escapeHTML(value)}"`);
}
}
}
Expand Down Expand Up @@ -93,8 +93,8 @@ export const serializeImage = (
const attributes = {
...generalAttributes,
src: node.url,
alt: node.alt && escapeHTML(node.alt),
copyright: node.copyright && escapeHTML(node.copyright),
alt: node.alt,
copyright: node.copyright,
};

let imageTag = `<img${formatAttributes(node, attributes)} />`;
Expand Down Expand Up @@ -153,7 +153,7 @@ export const serializeHyperlink = (
};

if (node.data.link_type === LinkType.Web) {
attributes.href = escapeHTML(node.data.url);
attributes.href = node.data.url;
attributes.target = node.data.target;
attributes.rel = "noopener noreferrer";
} else if (node.data.link_type === LinkType.Document) {
Expand Down
Loading

0 comments on commit 52ad75d

Please sign in to comment.