Skip to content
This repository was archived by the owner on Feb 24, 2025. It is now read-only.

Fix #586: encode image tag's src attribute #589

Merged
merged 1 commit into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/src/inline_syntaxes/image_syntax.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ class ImageSyntax extends LinkSyntax {
}) {
final element = Element.empty('img');
final children = getChildren();
element.attributes['src'] = destination;
element.attributes['src'] = normalizeLinkDestination(
escapePunctuation(destination),
);
element.attributes['alt'] = children.map((node) {
// See https://spec.commonmark.org/0.30/#image-description.
// An image description may contain links. Fetch text from the alt
Expand Down
5 changes: 5 additions & 0 deletions test/original/inline_images.unit
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,8 @@

<<<
<p><img src="http://foo.com/foo.png" alt="alt" /></p>
>>> XSS
![Uh oh...]("onerror="alert('XSS'))

<<<
<p><img src="%22onerror=%22alert('XSS')" alt="Uh oh..." /></p>