Skip to content
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 2.0.0 / 2025-09-02

* Potentially Breaking Change: `img` tags with base64 encoded `src` values,
which are not widely supported by markdown renderers, are removed to avoid
parser performance issues and crashes

## 1.1.0 / 2024-04-19
* basic handling for nested lists

Expand Down
6 changes: 5 additions & 1 deletion lib/upmark.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ def self.convert(html)
preprocess = Transform::Preprocess.new
markdown = Transform::Markdown.new

ast = xml.parse(html.strip)
# Remove base64 data URLs that cause parser issues
html = html.gsub(/(data:image\/[^;]*;base64,)[A-Za-z0-9+\/=]+/, '').strip

ast = xml.parse(html)

ast = normalise.apply(ast)
ast = preprocess.apply(ast)
ast = markdown.apply(ast)
Expand Down
2 changes: 1 addition & 1 deletion lib/upmark/transform/markdown.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def self.text(element)

element(:img) do |element|
attributes = map_attributes_subtree(element[:attributes])
href = attributes[:src]
href = attributes[:src].to_s
title = attributes[:title]
alt_text = attributes[:alt]

Expand Down
11 changes: 11 additions & 0 deletions spec/acceptance/upmark_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,17 @@ def actual
![messenger bag skateboard](http://helvetica.com/image.gif "art party organic")
MD
end

specify "removes base64 data URLs" do
expect(<<~HTML).to convert_to("")
<img src="data:image/png;base64,abc" />
HTML

src = "abc" * 10000
expect(<<~HTML).to convert_to("")
<img src="data:image/png;base64,#{src}" />
HTML
end
end

context "<p>" do
Expand Down