Commit 0faf772b authored by Stan Hu's avatar Stan Hu

Gracefully handle garbled URIs in Markdown

There are certain inputs that look like valid URIs that are accepted by URI
but not Addressable::URI. Handle the case where the latter fails.

Closes #41442
parent 46be07d2
---
title: Gracefully handle garbled URIs in Markdown
merge_request:
author:
type: fixed
......@@ -66,7 +66,7 @@ module Banzai
if uri.relative? && uri.path.present?
html_attr.value = rebuild_relative_uri(uri).to_s
end
rescue URI::Error
rescue URI::Error, Addressable::URI::InvalidURIError
# noop
end
......
......@@ -76,6 +76,11 @@ describe Banzai::Filter::RelativeLinkFilter do
expect { filter(act) }.not_to raise_error
end
it 'does not raise an exception with a garbled path' do
act = link("open(/var/tmp/):%20/location%0Afrom:%20/test")
expect { filter(act) }.not_to raise_error
end
it 'ignores ref if commit is passed' do
doc = filter(link('non/existent.file'), commit: project.commit('empty-branch') )
expect(doc.at_css('a')['href'])
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment