aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activerecord/CHANGELOG2
-rwxr-xr-xactiverecord/lib/active_record/fixtures.rb2
-rw-r--r--activerecord/test/fixtures/funny_jokes.yml10
-rwxr-xr-xactiverecord/test/fixtures_test.rb9
4 files changed, 15 insertions, 8 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index 3fdc4374d2..e83b737528 100644
--- a/activerecord/CHANGELOG
+++ b/activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Fixtures: correct escaping of \n and \r. #5859 [evgeny.zislis@gmail.com]
+
* Migrations: gracefully handle missing migration files. #5857 [eli.gordon@gmail.com]
* MySQL: update test schema for MySQL 5 strict mode. #5861 [Tom Ward]
diff --git a/activerecord/lib/active_record/fixtures.rb b/activerecord/lib/active_record/fixtures.rb
index 9062a96f41..f1aa1c1087 100755
--- a/activerecord/lib/active_record/fixtures.rb
+++ b/activerecord/lib/active_record/fixtures.rb
@@ -396,7 +396,7 @@ class Fixture #:nodoc:
list = @fixture.inject([]) do |fixtures, (key, value)|
col = klass.columns_hash[key] if klass.kind_of?(ActiveRecord::Base)
- fixtures << ActiveRecord::Base.connection.quote(value, col).gsub('\\n', "\n").gsub('\\r', "\r")
+ fixtures << ActiveRecord::Base.connection.quote(value, col).gsub('[^\]\\n', "\n").gsub('[^\]\\r', "\r")
end
list * ', '
end
diff --git a/activerecord/test/fixtures/funny_jokes.yml b/activerecord/test/fixtures/funny_jokes.yml
index 834481bc60..d47c4a6a10 100644
--- a/activerecord/test/fixtures/funny_jokes.yml
+++ b/activerecord/test/fixtures/funny_jokes.yml
@@ -4,11 +4,7 @@ a_joke:
another_joke:
id: 2
- name: The Aristocrats
-a_joke:
- id: 1
- name: Knock knock
+ name: |
+ The \n Aristocrats
+ Ate the candy
-another_joke:
- id: 2
- name: The Aristocrats \ No newline at end of file
diff --git a/activerecord/test/fixtures_test.rb b/activerecord/test/fixtures_test.rb
index e33d12e703..2f88feda3f 100755
--- a/activerecord/test/fixtures_test.rb
+++ b/activerecord/test/fixtures_test.rb
@@ -344,6 +344,15 @@ class InvalidTableNameFixturesTest < Test::Unit::TestCase
end
end
+class CheckEscapedYamlFixturesTest < Test::Unit::TestCase
+ set_fixture_class :funny_jokes => 'Joke'
+ fixtures :funny_jokes
+
+ def test_proper_escaped_fixture
+ assert_equal "The \\n Aristocrats\nAte the candy\n", funny_jokes(:another_joke).name
+ end
+end
+
class DevelopersProject; end;
class ManyToManyFixturesWithClassDefined < Test::Unit::TestCase