Skip to content

Commit b8eaacc

Browse files
committed
fix double-slashes in discussion notifications
closes #CNVS-35894 Change-Id: I53b01086031bf1022f47a0e0da838a5a131913c7 Reviewed-on: https://gerrit.instructure.com/106578 Tested-by: Jenkins Reviewed-by: Jeremy Stanley <jeremy@instructure.com> Product-Review: James Williams <jamesw@instructure.com> QA-Review: James Williams <jamesw@instructure.com>
1 parent 686e47f commit b8eaacc

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

gems/html_text_helper/lib/html_text_helper.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,11 @@ def append_base_url(subject, base)
160160
tags = output.css('*[href]')
161161

162162
tags.each do |tag|
163-
next if tag.attributes['href'].value.match(/^https?|mailto|ftp/)
164-
tag.attributes['href'].value = "#{base}#{tag.attributes['href']}"
163+
url = tag.attributes['href'].value
164+
next if url.match(/^https?|mailto|ftp/)
165+
166+
url.sub!("/", "") if url.start_with?("/") && base.end_with?("/")
167+
tag.attributes['href'].value = "#{base}#{url}"
165168
end
166169

167170
output.to_s

gems/html_text_helper/spec/html_text_helper_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,13 @@ def th
251251

252252
expect(html).to match(%r{http://example.com/relative/link})
253253
end
254+
255+
it "should resolve doubleslashes" do
256+
original_html = %q{ <a href="/relative/link">Relative link</a> }
257+
html = th.html_to_simple_html(original_html, base_url: 'http://example.com/')
258+
259+
expect(html).to match(%r{http://example.com/relative/link})
260+
end
254261
end
255262

256263
context "banner" do

0 commit comments

Comments
 (0)