# encoding: UTF-8 require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb') describe EscapeUtils, "escape_html" do it "should respond to escape_html" do EscapeUtils.should respond_to(:escape_html) end it "should escape a basic html tag, also escaping the '/' character if the secure parameter is true" do EscapeUtils.escape_html("").should eql("<some_tag/>") end it "should escape a basic html tag, not escaping the '/' character if the secure parameter is false" do EscapeUtils.escape_html("", false).should eql("<some_tag/>") end it "should escape a basic html tag, not escaping the '/' character if EscapeUtils.html_secure is false" do EscapeUtils.html_secure = false EscapeUtils.escape_html("").should eql("<some_tag/>") EscapeUtils.html_secure = true end it "should escape double-quotes" do EscapeUtils.escape_html("").should eql("<some_tag some_attr="some value"/>") end it "should escape single-quotes" do EscapeUtils.escape_html("").should eql("<some_tag some_attr='some value'/>") end it "should escape the & character" do EscapeUtils.escape_html("Bourbon & Branch").should eql("<b>Bourbon & Branch</b>") end if RUBY_VERSION =~ /^1.9/ it "should default to the original string's encoding if Encoding.default_internal is nil" do Encoding.default_internal = nil str = "Bourbon & Branch" str = str.encode('us-ascii') EscapeUtils.escape_html(str).encoding.should eql(Encoding.find('us-ascii')) end it "should use Encoding.default_internal" do Encoding.default_internal = Encoding.find('utf-8') EscapeUtils.escape_html("Bourbon & Branch").encoding.should eql(Encoding.default_internal) Encoding.default_internal = Encoding.find('us-ascii') EscapeUtils.escape_html("Bourbon & Branch").encoding.should eql(Encoding.default_internal) end end end