proposed fix for issue 461 #462

Merged
merged 1 commit into from Apr 3, 2012
Jump to file or symbol
Failed to load files and symbols.
+46 −1
Split
@@ -616,7 +616,7 @@ def literal_blob_append(sql, v)
# backslashes.
def literal_string_append(sql, v)
sql << (mssql_unicode_strings ? UNICODE_STRING_START : APOS)
- sql << v.gsub(APOS_RE, DOUBLE_APOS) << APOS
+ sql << v.gsub(APOS_RE, DOUBLE_APOS).sub(/(\x5C)((?:\x0D\x0A)|\x0A)\z/, '\1\1\2\2') << APOS
end
# Use 0 for false on MSSQL
@@ -520,6 +520,51 @@ def transaction(opts={})
end
end
+describe "MSSQL::Dataset#literal" do
+ before do
+ @db = MSSQL_DB
+ @db.create_table!(:test_literal){String :name}
+ @ds = MSSQL_DB[:test_literal]
+ end
+ after do
+ @db.drop_table? :test_literal
+ end
+
+ context "when value ends with backslash + crlf/lf" do
+ specify "should escape" do
+ @ds.literal("\\").should == "N'\\'"
+ @ds.literal("\\\r").should == "N'\\\r'"
+ @ds.literal("\\\r\r").should == "N'\\\r\r'"
+ @ds.literal("\\\n\r").should == "N'\\\n\r'"
+ @ds.literal("\\\r\nX").should == "N'\\\r\nX'"
+ @ds.literal("\\\r\n\n").should == "N'\\\r\n\n'"
+ @ds.literal("\\\r\n\r").should == "N'\\\r\n\r'"
+
+ @ds.literal("\\\n").should == "N'\\\\\n\n'"
+ @ds.literal("\\\r\n").should == "N'\\\\\r\n\r\n'"
+ end
+ specify "makes roundtrip" do
+ ["\\\n",
+ "\\\\\n",
+ "\\\r\n",
+ "\\\\\r\n"].each do |str|
+ @ds.delete
+ @ds.insert(:name => str)
+ @ds.select_map(:name).should == [str]
+ end
+ end
+ specify "allows values with escape sequence" do
+ pending("need to the fastest way to detect this case")
+ ["\\\\\n\n",
+ "\\\\\r\n\r\n"].each do |str|
+ @ds.delete
+ @ds.insert(:name => str)
+ @ds.select_map(:name).should == [str]
+ end
+ end
+ end
+end
+
describe "A MSSQL database adds index with include" do
before :all do
@table_name = :test_index_include