From eb1e1f495f864f24897303b5d64b3185fae869dd Mon Sep 17 00:00:00 2001 From: chiheb ben cheikh <100644963+ChihebBENCHEIKH1@users.noreply.github.com> Date: Sat, 19 Sep 2026 13:11:13 +0100 Subject: [PATCH] json-schema : accept escaped hyphen in regex patterns (#29127) --- common/json-schema-to-grammar.cpp | 3 ++- tests/test-json-schema-to-grammar.cpp | 28 ++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/common/json-schema-to-grammar.cpp b/common/json-schema-to-grammar.cpp index e0426098c..3349ae4fe 100644 --- a/common/json-schema-to-grammar.cpp +++ b/common/json-schema-to-grammar.cpp @@ -321,7 +321,8 @@ static size_t gbnf_escape_length(const std::string & pattern, size_t pos) { case 'x': n_hex = 2; break; case 'u': n_hex = 4; break; case 'U': n_hex = 8; break; - case 't': case 'r': case 'n': case '\\': case '"': case '[': case ']': + // keep in sync with parse_char() in src/llama-grammar.cpp + case 't': case 'r': case 'n': case '\\': case '"': case '[': case ']': case '-': return 2; default: return 0; diff --git a/tests/test-json-schema-to-grammar.cpp b/tests/test-json-schema-to-grammar.cpp index 4c4206c6e..d5873c19d 100755 --- a/tests/test-json-schema-to-grammar.cpp +++ b/tests/test-json-schema-to-grammar.cpp @@ -1476,6 +1476,32 @@ static void test_all(const std::string & title, std::function