Permalink
Browse files

Fix issue with handling multi-line content

  • Loading branch information...
1 parent c7f9305 commit ef99da06fc63dacf95f9568439459835a16fddf5 @tlconnor committed Aug 5, 2012
Showing with 6 additions and 2 deletions.
  1. +1 −1 activerecord-postgres-array.gemspec
  2. +1 −1 lib/activerecord-postgres-array/string.rb
  3. +4 −0 spec/string_ext_spec.rb
View
2 activerecord-postgres-array.gemspec
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = "activerecord-postgres-array"
- s.version = "0.0.7"
+ s.version = "0.0.8"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Tim Connor"]
View
2 lib/activerecord-postgres-array/string.rb
@@ -20,7 +20,7 @@ def from_postgres_array(base_type = :string)
if empty?
[]
else
- elements = match(/\{(.*)\}/).captures.first.gsub(/\\"/, '$ESCAPED_DOUBLE_QUOTE$').split(/(?:,)(?=(?:[^"]|"[^"]*")*$)/)
+ elements = match(/\{(.*)\}/m).captures.first.gsub(/\\"/, '$ESCAPED_DOUBLE_QUOTE$').split(/(?:,)(?=(?:[^"]|"[^"]*")*$)/m)
elements = elements.map do |e|
res = e.gsub('$ESCAPED_DOUBLE_QUOTE$', '"').gsub("\\\\", "\\").gsub(/^"/, '').gsub(/"$/, '').gsub("''", "'").strip
res == 'NULL' ? nil : res
View
4 spec/string_ext_spec.rb
@@ -101,5 +101,9 @@
it 'correctly handles backslashes' do
'\'{"\\\\","\\""}\''.from_postgres_array.should == ["\\","\""]
end
+
+ it 'correctly handles multi line content' do
+ "{A\nB\nC,X\r\nY\r\nZ}".from_postgres_array.should == ["A\nB\nC", "X\r\nY\r\nZ"]
+ end
end
end

0 comments on commit ef99da0

Please sign in to comment.