", "", ""]
_ = "%s %s %s".html_safe % @other_string
assert_equal ["
", "", ""], @other_string
end
test "Concatting an integer to safe always yields safe" do
string = @string.html_safe
string = string.concat(13)
assert_equal "hello".dup.concat(13), string
assert string.html_safe?
end
test "emits normal string yaml" do
assert_equal "foo".to_yaml, "foo".html_safe.to_yaml(foo: 1)
end
test "call to_param returns a normal string" do
string = @string.html_safe
assert string.html_safe?
assert !string.to_param.html_safe?
end
test "ERB::Util.html_escape should escape unsafe characters" do
string = '<>&"\''
expected = "<>&"'"
assert_equal expected, ERB::Util.html_escape(string)
end
test "ERB::Util.html_escape should correctly handle invalid UTF-8 strings" do
string = "\251 <"
expected = "© <"
assert_equal expected, ERB::Util.html_escape(string)
end
test "ERB::Util.html_escape should not escape safe strings" do
string = "hello".html_safe
assert_equal string, ERB::Util.html_escape(string)
end
test "ERB::Util.html_escape_once only escapes once" do
string = "1 < 2 & 3"
escaped_string = "1 < 2 & 3"
assert_equal escaped_string, ERB::Util.html_escape_once(string)
assert_equal escaped_string, ERB::Util.html_escape_once(escaped_string)
end
test "ERB::Util.html_escape_once should correctly handle invalid UTF-8 strings" do
string = "\251 <"
expected = "© <"
assert_equal expected, ERB::Util.html_escape_once(string)
end
end
class StringExcludeTest < ActiveSupport::TestCase
test "inverse of #include" do
assert_equal false, "foo".exclude?("o")
assert_equal true, "foo".exclude?("p")
end
end
class StringIndentTest < ActiveSupport::TestCase
test "does not indent strings that only contain newlines (edge cases)" do
["", "\n", "\n" * 7].each do |string|
str = string.dup
assert_nil str.indent!(8)
assert_equal str, str.indent(8)
assert_equal str, str.indent(1, "\t")
end
end
test "by default, indents with spaces if the existing indentation uses them" do
assert_equal " foo\n bar", "foo\n bar".indent(4)
end
test "by default, indents with tabs if the existing indentation uses them" do
assert_equal "\tfoo\n\t\t\bar", "foo\n\t\bar".indent(1)
end
test "by default, indents with spaces as a fallback if there is no indentation" do
assert_equal " foo\n bar\n baz", "foo\nbar\nbaz".indent(3)
end
# Nothing is said about existing indentation that mixes spaces and tabs, so
# there is nothing to test.
test "uses the indent char if passed" do
assert_equal <