Skip to content

Commit

Permalink
Allow escaped strings in json_schema.py
Browse files Browse the repository at this point in the history
  • Loading branch information
lapp0 authored and rlouf committed Jun 20, 2024
1 parent 371313e commit a9d58ef
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 3 additions & 1 deletion outlines/fsm/json_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
from referencing._core import Resolver
from referencing.jsonschema import DRAFT202012

STRING_INNER = r'([^"\\\x00-\x1f\x7f-\x9f]|\\\\)'
# allow `\"`, `\\`, or any character which isn't a control sequence
STRING_INNER = r'([^"\\\x00-\x1F\x7F-\x9F]|\\["\\])'
STRING = f'"{STRING_INNER}*"'

INTEGER = r"(-)?(0|[1-9][0-9]*)"
NUMBER = rf"({INTEGER})(\.[0-9]+)?([eE][+-][0-9]+)?"
BOOLEAN = r"(true|false)"
Expand Down
4 changes: 4 additions & 0 deletions tests/fsm/test_json_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ def test_match_number(pattern, does_match):
('"quoted_string"', True),
(r'"escape_\character"', False),
(r'"double_\\escape"', True),
(r'"\n"', False),
(r'"\\n"', True),
(r'"unescaped " quote"', False),
(r'"escaped \" quote"', True),
],
),
# String with maximum length
Expand Down

0 comments on commit a9d58ef

Please sign in to comment.