Commit 8e38ca94 authored by Sean McGivern's avatar Sean McGivern

Merge branch '57227-absolute-uri-missing-hierarchical-segment' into 'master'

Fix ActionView::Template::Error: Absolute URI missing hierarchical segment

Closes #57227

See merge request gitlab-org/gitlab-ce!24908
parents 7f880007 7e25ff30
---
title: Fix potential Addressable::URI::InvalidURIError
merge_request: 24908
author:
type: fixed
......@@ -114,7 +114,11 @@ module Banzai
# Since this came from a Text node, make sure the new href is encoded.
# `commonmarker` percent encodes the domains of links it handles, so
# do the same (instead of using `normalized_encode`).
begin
href_safe = Addressable::URI.encode(match).html_safe
rescue Addressable::URI::InvalidURIError
return uri.to_s
end
html_safe_match = match.html_safe
options = link_options.merge(href: href_safe)
......
......@@ -121,6 +121,13 @@ describe Banzai::Filter::AutolinkFilter do
expect(doc.to_s).to eq("See #{link}")
end
it 'does not autolink bad URLs after we remove trailing punctuation' do
link = 'http://]'
doc = filter("See #{link}")
expect(doc.to_s).to eq("See #{link}")
end
it 'does not include trailing punctuation' do
['.', ', ok?', '...', '?', '!', ': is that ok?'].each do |trailing_punctuation|
doc = filter("See #{link}#{trailing_punctuation}")
......
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