Skip to content

Commit 9fcfe8c

Browse files
committed
String#from_postgres_array accept NULL
1 parent ff12890 commit 9fcfe8c

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

lib/activerecord-postgres-array/string.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ def from_postgres_array(base_type = :string)
2222
else
2323
elements = match(/\{(.*)\}/).captures.first.gsub(/\\"/, '$ESCAPED_DOUBLE_QUOTE$').split(/(,)(?=(?:[^"]|"[^"]*")*$)/).reject {|e| e == ',' }
2424
elements = elements.map do |e|
25-
e.gsub('$ESCAPED_DOUBLE_QUOTE$', '"').gsub("\\\\", "\\").gsub(/^"/, '').gsub(/"$/, '').gsub("''", "'").strip
25+
res = e.gsub('$ESCAPED_DOUBLE_QUOTE$', '"').gsub("\\\\", "\\").gsub(/^"/, '').gsub(/"$/, '').gsub("''", "'").strip
26+
res == 'NULL' ? nil : res
2627
end
2728

2829
if base_type == :decimal

0 commit comments

Comments
 (0)