@@ -61,19 +61,28 @@ def each_filter
61
61
# foo,bar,baz becomes ["foo", "bar", "baz"]
62
62
# {{foo}} becomes ["foo"]
63
63
# {{foo,bar}},baz becomes ["foo,bar", "baz"]
64
+ #
65
+ # JSON of
66
+ # {{{ "id": 1 }}} becomes { 'id' => 1 }
64
67
def parse_string_arrays ( value )
65
- if value . is_a? ( String )
66
- # Find the quoted strings
67
- quotes = value . scan ( /{{.*?}}/ )
68
- # remove them from the rest
69
- quotes . each { |q | value . gsub! ( q , '' ) }
70
- # remove the quote characters from the quoted strings
71
- quotes . each { |q | q . gsub! ( '{{' , '' ) . gsub! ( '}}' , '' ) }
72
- # merge everything back together into an array
73
- value = Array ( value . split ( ',' ) ) + quotes
74
- # remove any blanks that are left
75
- value . reject! { |v | v . length . zero? }
76
- value = value [ 0 ] if value . length == 1
68
+ if value . is_a? ( String ) # && value[0..2] != '{{{'
69
+ # Escaped JSON
70
+ if value [ 0 ..2 ] == '{{{'
71
+ value = value . sub ( '{{' , '' ) . sub ( '}}' , '' )
72
+ value = JSON . parse ( value )
73
+ else
74
+ # Find the quoted strings
75
+ quotes = value . scan ( /{{.*?}}/ )
76
+ # remove them from the rest
77
+ quotes . each { |q | value . gsub! ( q , '' ) }
78
+ # remove the quote characters from the quoted strings
79
+ quotes . each { |q | q . gsub! ( '{{' , '' ) . gsub! ( '}}' , '' ) }
80
+ # merge everything back together into an array
81
+ value = Array ( value . split ( ',' ) ) + quotes
82
+ # remove any blanks that are left
83
+ value . reject! { |v | v . length . zero? }
84
+ value = value [ 0 ] if value . length == 1
85
+ end
77
86
end
78
87
value
79
88
end
0 commit comments