Skip to content

Commit

Permalink
Fix quoted string parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
frodrigo committed Apr 15, 2024
1 parent dba8383 commit b0bba1c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 9 additions & 1 deletion lib/overpass_parser/visitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,15 @@ def visit_filter(ctx)

def visit_token(ctx)
visit_children(ctx)
text = !ctx.UNQUOTED_STRING.nil? || !ctx.number.nil? ? (ctx.UNQUOTED_STRING || ctx.number).text : ctx.text[1..-2]
text = (
if !ctx.SIMPLE_QUOTED_STRING.nil?
ctx.text[1..-2].gsub("\\'", "'")
elsif !ctx.DOUBLE_QUOTED_STRING.nil?
ctx.text[1..-2].gsub('\\"', '"')
else
(ctx.UNQUOTED_STRING || ctx.number).text
end
)
@stack.push(text)
end
end
Expand Down
4 changes: 2 additions & 2 deletions test/overpass_parser/visitor_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def test_to_sql
[out:json][timeout:25];
area(3600166718)->.a;
(
nwr[a="Ñ"](area.a)->.x;
nwr[a="Ñ\'\\""][b=\'"\'](area.a)->.x;
nwr[c](area.a)->.z;
)->.k;
out center meta;
Expand All @@ -142,7 +142,7 @@ def test_to_sql
nwr
WHERE
osm_type = ANY (ARRAY['n', 'w', 'r']) AND
(tags?'a' AND tags->>'a' = 'Ñ') AND
(tags?'a' AND tags->>'a' = 'Ñ''\"') AND (tags?'b' AND tags->>'b' = '\"') AND
ST_Intersects(geom, (SELECT ST_Union(geom) FROM _a))
),
_z AS (
Expand Down

0 comments on commit b0bba1c

Please sign in to comment.