Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

proposed fix for issue 461 #462

Merged
merged 1 commit into from

2 participants

@munkyboy

No description provided.

@jeremyevans
Owner

This looks pretty good. I'll probably make some minor changes when I merge it. Thanks!

@jeremyevans jeremyevans merged commit b140e79 into jeremyevans:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
2  lib/sequel/adapters/shared/mssql.rb
@@ -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
View
45 spec/adapters/mssql_spec.rb
@@ -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
Something went wrong with that request. Please try again.