Skip to content

Commit

Permalink
Make sure to convert the objects to a String before escaping and/or q…
Browse files Browse the repository at this point in the history
…uoting
  • Loading branch information
copiousfreetime committed Jan 25, 2009
1 parent 1feb33d commit bcada7b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion ext/amalgalite3.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ VALUE am_sqlite3_set_temp_directory( VALUE self, VALUE new_dir )

VALUE amalgalite_format_string( char* pattern, VALUE string )
{
VALUE str = StringValue( string );
VALUE to_s= rb_funcall( string, rb_intern("to_s"), 0 );
VALUE str = StringValue( to_s );
char *p = sqlite3_mprintf(pattern, RSTRING(str)->ptr);
VALUE rv = Qnil;
if ( NULL != p ) {
Expand Down
8 changes: 8 additions & 0 deletions spec/database_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -390,4 +390,12 @@ def call( *args) "ftest5 called"; end
@iso_db.quote( "It's a happy day!" ).should == "'It''s a happy day!'"
end

it "can escape a symbol" do
@iso_db.escape( :stuff ).should == "stuff"
end

it "can quote a symbol" do
@iso_db.quote( :stuff ).should == "'stuff'"
end

end
10 changes: 10 additions & 0 deletions spec/sqlite3_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,17 @@
Amalgalite::SQLite3.escape( "It's a happy day!" ).should == "It''s a happy day!"
end

it "can escape a symble into a string" do
Amalgalite::SQLite3.escape( :stuff ).should == "stuff"
Amalgalite::SQLite3.escape( :"stuff'n" ).should == "stuff''n"
end

it "can quote and escape single quoted strings" do
Amalgalite::SQLite3.quote( "It's a happy day!" ).should == "'It''s a happy day!'"
end

it "can quote and escape symbols" do
Amalgalite::SQLite3.quote( :stuff ).should == "'stuff'"
Amalgalite::SQLite3.quote( :"stuff'n" ).should == "'stuff''n'"
end
end

0 comments on commit bcada7b

Please sign in to comment.