html_node_to_text doesn't emit src-less images

fixes CNVS-13449

test plan
- create a discussion topic with an image without a src attribute
- ensure that notification is sent for the topic

Change-Id: Idb87eaa955089197aaaa2247cc6172d8dd52c6ba
Reviewed-on: https://gerrit.instructure.com/36756
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Braden Anderson <braden@instructure.com>
QA-Review: David Josse <david@instructure.com>
Product-Review: Joel Hough <joel@instructure.com>
This commit is contained in:
Joel Hough 2014-06-23 15:04:18 -06:00
parent 7f49fc8ad1
commit ef0fbc9f87
2 changed files with 14 additions and 2 deletions

View File

@ -66,8 +66,12 @@ module HtmlTextHelper
node.children.map{|c| html_node_to_text(c, opts.merge(pre: true))}.join
when 'img'
src = node['src']
src = URI.join(opts[:base_url], src) if opts[:base_url]
node['alt'] ? "[#{node['alt']}](#{src})" : src
if src
src = URI.join(opts[:base_url], src) if opts[:base_url]
node['alt'] ? "[#{node['alt']}](#{src})" : src
else
''
end
when 'br'
"\n"
else

View File

@ -92,6 +92,10 @@ describe HtmlTextHelper do
th.html_to_text('<img alt="an image" src="/image.png"').should == "[an image](/image.png)"
end
it "should not format src-less images" do
th.html_to_text('<img alt="an image">').should == ''
end
it "should add base urls to links" do
th.html_to_text('<a href="/link">Link</a>', base_url: "http://example.com").should == "[Link](http://example.com/link)"
th.html_to_text('<a href="http://example.org/link">Link</a>', base_url: "http://example.com").should == "[Link](http://example.org/link)"
@ -102,6 +106,10 @@ describe HtmlTextHelper do
th.html_to_text('<img src="http://example.org/image.png" />', base_url: "http://example.com").should == "http://example.org/image.png"
end
it "should not format src-less images even with base urls" do
th.html_to_text('<img alt="an image">', base_url: "http://example.com").should == ''
end
it "should format list elements" do
th.html_to_text("<li>Item 1</li><li>Item 2</li>\n<li>Item 3</li> <li>Item 4\n<li> Item 5").should == <<EOS.strip
* Item 1