Skip to content

fix sqlite3 column default containing newline character #7088

Closed
wants to merge 1 commit into from

4 participants

@mdominiak

Due to incorrect parsing of sqlite3 string column default containing newline character, any string column default containing newline character, e.g. "\n" or "\nRegards\nMatt" is parsed incorrectly by sqlite3 adapter and as a result contains enclosing quote characters ('), e.g. "'\n'" or "'\nRegards\nMatt'".

The regular expressions stripping column defaults out of enclosing quote/double quote characters did not take into consideration column defaults containing newline characters. More specifically /^'(.*)'$/ regular expression would not match "'\n'" since dot (.) in this expression is intended to match any character except for newline character and hence column default was not stripped correctly out of enclosing quotes returned by database when querying for table structure.

@mdominiak mdominiak fix sqlite3 column default containing newline
Due to incorrect parsing of text/string column default containing
newline character, string column default "\n" ended up being
"'\n'" default.
60548b0
@rafaelfranca rafaelfranca commented on the diff Jul 18, 2012
...d/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
@@ -272,6 +272,19 @@ def test_columns_with_default
}
assert_equal 10, column.default
end
+
+ def test_column_with_newline_default
+ @conn.execute <<-eosql
@rafaelfranca
Ruby on Rails member
rafaelfranca added a note Jul 18, 2012

This will change the state of the database in all the tests. I think we should drop the table after this test using a ensure block

@mdominiak
mdominiak added a note Jul 18, 2012

In setup there is new in-memory sqlite3 database created before each test so created tables are not visible to other tests:
https://github.com/rails/rails/blob/master/activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb#L14

I followed the convention in sqlite3_adapter_test.rb. There are many other tables created in similar fashion there and not dropped afterwards. For example, that is the other test for default value:
https://github.com/rails/rails/blob/master/activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb#L263

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@steveklabnik
Ruby on Rails member

This will need a rebase.

@tenderlove
Ruby on Rails member

I think this was fixed in 3e8ab91

@mdominiak

Yes, this is the same fix as in 3e8ab91. I'm closing this issue.

@mdominiak mdominiak closed this Sep 23, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.