提交 aa31d21f 编写于 作者: S Sean Griffin

Don't default to YAML dumping when quoting values

This behavior exists only to support fixtures, so we should handle it
there. Leaving it in `#quote` can cause very subtle bugs to slip
through, by things appearing to work when they should be blowing up
loudly, such as #18385.
上级 855cca06
......@@ -289,7 +289,13 @@ def insert_fixture(fixture, table_name)
[columns[name], value]
end
key_list = fixture.keys.map { |name| quote_column_name(name) }
value_list = prepare_binds_for_database(binds).map { |_, value| quote(value) }
value_list = prepare_binds_for_database(binds).map do |_, value|
begin
quote(value)
rescue TypeError
quote(YAML.dump(value))
end
end
execute "INSERT INTO #{quote_table_name(table_name)} (#{key_list.join(', ')}) VALUES (#{value_list.join(', ')})", 'Fixture Insert'
end
......
......@@ -125,8 +125,7 @@ def _quote(value)
when Date, Time then "'#{quoted_date(value)}'"
when Symbol then "'#{quote_string(value.to_s)}'"
when Class then "'#{value}'"
else
"'#{quote_string(YAML.dump(value))}'"
else raise TypeError, "can't quote #{value.class.name}"
end
end
......
......@@ -125,14 +125,11 @@ def test_dates_and_times
end
def test_crazy_object
crazy = Class.new.new
expected = "'#{YAML.dump(crazy)}'"
assert_equal expected, @quoter.quote(crazy, nil)
end
def test_crazy_object_calls_quote_string
crazy = Class.new { def initialize; @lol = 'lo\l' end }.new
assert_match "lo\\\\l", @quoter.quote(crazy, nil)
crazy = Object.new
e = assert_raises(TypeError) do
@quoter.quote(crazy, nil)
end
assert_equal "can't quote Object", e.message
end
def test_quote_string_no_column
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册