Skip to content

Commit

Permalink
Exclude escape character in JSON string fields
Browse files Browse the repository at this point in the history
  • Loading branch information
rlouf committed Apr 20, 2024
1 parent 2182dbc commit 06d5654
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion outlines/fsm/json_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from referencing._core import Resolver
from referencing.jsonschema import DRAFT202012

STRING_INNER = r'(?:[^"\\\x00-\x1f\x7f-\x9f]|\\.)'
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]+)?"
Expand Down
7 changes: 6 additions & 1 deletion tests/fsm/test_json_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,12 @@ def test_match_number(pattern, does_match):
(
{"title": "Foo", "type": "string"},
STRING,
[("unquotedstring", False), ('"quoted_string"', True)],
[
("unquotedstring", False),
('"quoted_string"', True),
(r'"escape_\character"', False),
(r'"double_\\escape"', True),
],
),
# String with maximum length
(
Expand Down

0 comments on commit 06d5654

Please sign in to comment.