@@ -133,6 +133,20 @@ func TestGemma4Parser(t *testing.T) {
133133 },
134134 },
135135 },
136+ {
137+ name : "tool_call_with_array_of_multiple_gemma_quoted_strings" ,
138+ input : `<|tool_call>call:process{items:[<|"|>a<|"|>,<|"|>b "quoted"<|"|>,<|"|>c<|"|>]}<tool_call|>` ,
139+ expectedToolCalls : []api.ToolCall {
140+ {
141+ Function : api.ToolCallFunction {
142+ Name : "process" ,
143+ Arguments : testArgs (map [string ]any {
144+ "items" : []any {"a" , `b "quoted"` , "c" },
145+ }),
146+ },
147+ },
148+ },
149+ },
136150 {
137151 name : "tool_call_with_multiline_string_arg" ,
138152 input : `<|tool_call>call:bash{command:<|"|>date
@@ -148,6 +162,62 @@ func TestGemma4Parser(t *testing.T) {
148162 },
149163 },
150164 },
165+ {
166+ name : "tool_call_with_escaped_double_quotes_in_string_arg" ,
167+ input : `<|tool_call>call:search{query:<|"|>say \"hello\"<|"|>}<tool_call|>` ,
168+ expectedToolCalls : []api.ToolCall {
169+ {
170+ Function : api.ToolCallFunction {
171+ Name : "search" ,
172+ Arguments : testArgs (map [string ]any {
173+ "query" : `say "hello"` ,
174+ }),
175+ },
176+ },
177+ },
178+ },
179+ {
180+ name : "tool_call_with_unescaped_double_quotes_in_string_arg" ,
181+ input : `<|tool_call>call:search{query:<|"|>say "hello"<|"|>}<tool_call|>` ,
182+ expectedToolCalls : []api.ToolCall {
183+ {
184+ Function : api.ToolCallFunction {
185+ Name : "search" ,
186+ Arguments : testArgs (map [string ]any {
187+ "query" : `say "hello"` ,
188+ }),
189+ },
190+ },
191+ },
192+ },
193+ {
194+ name : "tool_call_with_multiple_unescaped_double_quote_segments" ,
195+ input : `<|tool_call>call:search{query:<|"|>say "hello", then "goodbye"<|"|>}<tool_call|>` ,
196+ expectedToolCalls : []api.ToolCall {
197+ {
198+ Function : api.ToolCallFunction {
199+ Name : "search" ,
200+ Arguments : testArgs (map [string ]any {
201+ "query" : `say "hello", then "goodbye"` ,
202+ }),
203+ },
204+ },
205+ },
206+ },
207+ {
208+ name : "tool_call_with_mixed_escaped_and_unescaped_double_quotes" ,
209+ input : `<|tool_call>call:search{query:<|"|>first \"quoted\" then "raw"<|"|>}<tool_call|>` ,
210+ expectedToolCalls : []api.ToolCall {
211+ {
212+ Function : api.ToolCallFunction {
213+ Name : "search" ,
214+ Arguments : testArgs (map [string ]any {
215+ "query" : `first "quoted" then "raw"` ,
216+ }),
217+ },
218+ },
219+ },
220+ },
151221 {
152222 name : "multiple_tool_calls" ,
153223 input : `<|tool_call>call:get_weather{location:<|"|>Paris<|"|>}<tool_call|><|tool_call>call:get_weather{location:<|"|>London<|"|>}<tool_call|>` ,
@@ -410,6 +480,11 @@ func TestGemma4ArgsToJSON(t *testing.T) {
410480 input : `{items:[<|"|>a<|"|>,<|"|>b<|"|>]}` ,
411481 expected : `{"items":["a","b"]}` ,
412482 },
483+ {
484+ name : "array_value_with_multiple_gemma_quoted_strings" ,
485+ input : `{items:[<|"|>a<|"|>,<|"|>b "quoted"<|"|>,<|"|>c<|"|>]}` ,
486+ expected : `{"items":["a","b \"quoted\"","c"]}` ,
487+ },
413488 {
414489 name : "empty_object" ,
415490 input : `{}` ,
@@ -431,6 +506,26 @@ func TestGemma4ArgsToJSON(t *testing.T) {
431506<|"|>}` ,
432507 expected : `{"command":"date\n"}` ,
433508 },
509+ {
510+ name : "string_value_with_escaped_double_quotes" ,
511+ input : `{query:<|"|>say \"hello\"<|"|>}` ,
512+ expected : `{"query":"say \"hello\""}` ,
513+ },
514+ {
515+ name : "string_value_with_unescaped_double_quotes" ,
516+ input : `{query:<|"|>say "hello"<|"|>}` ,
517+ expected : `{"query":"say \"hello\""}` ,
518+ },
519+ {
520+ name : "string_value_with_multiple_unescaped_double_quote_segments" ,
521+ input : `{query:<|"|>say "hello", then "goodbye"<|"|>}` ,
522+ expected : `{"query":"say \"hello\", then \"goodbye\""}` ,
523+ },
524+ {
525+ name : "string_value_with_mixed_escaped_and_unescaped_double_quotes" ,
526+ input : `{query:<|"|>first \"quoted\" then "raw"<|"|>}` ,
527+ expected : `{"query":"first \"quoted\" then \"raw\""}` ,
528+ },
434529 }
435530
436531 for _ , tt := range tests {
0 commit comments