[Fix #1078] Fix a crasher in HtmlToStringHelper
This commit is contained in:
parent
2a14993374
commit
04d17a2ed0
2 changed files with 14 additions and 5 deletions
|
@ -1,5 +1,8 @@
|
|||
module HtmlToStringHelper
|
||||
def html_to_string(html)
|
||||
if html.blank?
|
||||
html
|
||||
else
|
||||
string_with_tags = html
|
||||
.gsub(/<br[ ]?[\/]?>/, "\n")
|
||||
.gsub('</p>', "\n")
|
||||
|
@ -7,4 +10,5 @@ module HtmlToStringHelper
|
|||
|
||||
strip_tags(string_with_tags)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,6 +4,11 @@ describe HtmlToStringHelper do
|
|||
it { expect(helper.html_to_string('text')).to eq('text') }
|
||||
end
|
||||
|
||||
describe 'deals with empty / nil strings' do
|
||||
it { expect(helper.html_to_string(nil)).to eq(nil) }
|
||||
it { expect(helper.html_to_string('')).to eq("") }
|
||||
end
|
||||
|
||||
describe 'deals with <br>' do
|
||||
it { expect(helper.html_to_string('new<br>line')).to eq("new\nline") }
|
||||
it { expect(helper.html_to_string('new<br/>line')).to eq("new\nline") }
|
||||
|
|
Loading…
Reference in a new issue