diff --git a/app/helpers/html_helper.rb b/app/helpers/html_helper.rb index 85dc5b1c53..c648cf3ace 100644 --- a/app/helpers/html_helper.rb +++ b/app/helpers/html_helper.rb @@ -1,5 +1,5 @@ module HtmlHelper def strip_html(html) - strip_tags(html).gsub(/ /i, ' ').gsub(/&/i, '&') + strip_tags(html).andand.gsub(/ /i, ' ').andand.gsub(/&/i, '&') end end diff --git a/spec/helpers/html_helper_spec.rb b/spec/helpers/html_helper_spec.rb new file mode 100644 index 0000000000..606d301cbd --- /dev/null +++ b/spec/helpers/html_helper_spec.rb @@ -0,0 +1,27 @@ +require 'spec_helper' + +describe HtmlHelper do + class HelperStub + extend ActionView::Helpers::SanitizeHelper::ClassMethods + include ActionView::Helpers::SanitizeHelper + end + + subject do + obj = HelperStub.new + obj.extend HtmlHelper + end + + describe "stripping html from a string" do + it "strips tags" do + subject.strip_html('
Hello world!
').should == 'Hello world!' + end + + it "removes nbsp and amp entities" do + subject.strip_html('Hello world&&').should == 'Hello world&&' + end + + it "returns nil for nil input" do + subject.strip_html(nil).should be_nil + end + end +end