Skip to content

Commit

Permalink
Fix dart-lang#586: encode image tag's src attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
tomyeh committed Feb 23, 2024
1 parent d735b0b commit c39670e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
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>

0 comments on commit c39670e

Please sign in to comment.