json-schema: a pattern without ^ or $ searches, as JSON Schema reads it

_visit_pattern() read only ^...$ and refused every other `pattern` with "Pattern must start
with '^' and end with '$'". JSON Schema patterns are unanchored (ECMA-262 search, validation
6.3.3). Since 1.8 constrains tool-call arguments with a grammar, a bare pattern on array items
failed the whole request: an opencode agent's tool list did, on every request.

A missing anchor is now written out as any string text on that side, (?:[^"\\]|\\.)*, not ".*"
('.' matches '"' here, so on array items ["1","x"] read as one string holding a digit). A
one-sided anchor beside a top-level '|' is still refused. vendor/patches/0017, vendor/UPSTREAM;
tests in gbnf_test (json_schema_grammars_admit_exactly_their_instances) and sample_test (an
empty pattern now matches every string).
This commit is contained in:
davetha authored and StillDeadcode committed 2026-10-19 10:38:06 +02:00
1 parent 35b357825e
commit 52f47505c2
5 files changed
+140 -4

No files matched your search

+4 -3
View File
@@ -1123,10 +1123,11 @@ TEST(json_schema_refuses_what_it_cannot_actually_enforce) {
"{\"type\":\"string\",\"pattern\":\"^a]$\"}", "root", &gbnf, &err) < 0);
CHECK(!err.empty());
/* An empty pattern would run front()/back() on an empty string. */
/* An empty pattern would run front()/back() on an empty string. Unanchored, as JSON Schema
* reads it, it now matches every string and never reaches them (vendor patch 0017). */
err.clear();
CHECK(grammar_from_json_schema(
"{\"type\":\"string\",\"pattern\":\"\"}", "root", &gbnf, &err) < 0);
CHECK_OK(grammar_from_json_schema(
"{\"type\":\"string\",\"pattern\":\"\"}", "root", &gbnf, &err));
/* A leading quantifier would run back() on an empty vector. */
err.clear();