Skip to content

Commit

Permalink
Escape JSON property names in regex
Browse files Browse the repository at this point in the history
  • Loading branch information
sami-t authored and rlouf committed Mar 3, 2024
1 parent 88dc97c commit 0488ad2
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion outlines/fsm/json_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def to_regex(
if any(is_required):
last_required_pos = max([i for i, value in enumerate(is_required) if value])
for i, (name, value) in enumerate(properties.items()):
subregex = f'{whitespace_pattern}"{name}"{whitespace_pattern}:{whitespace_pattern}'
subregex = f'{whitespace_pattern}"{re.escape(name)}"{whitespace_pattern}:{whitespace_pattern}'
subregex += to_regex(resolver, value, whitespace_pattern)
if i < last_required_pos:
subregex = f"{subregex}{whitespace_pattern},"
Expand Down

0 comments on commit 0488ad2

Please sign in to comment.