@@ -138,6 +138,47 @@ describe('parseToolCallArguments', () => {
138138 expect ( result ) . toEqual ( { success : true , data : { a : '\\u12ZZ' } } ) ;
139139 } ) ;
140140
141+ it ( 'repairs unescaped quotes inside items-array string values' , ( ) => {
142+ const result = parseToolCallArguments (
143+ '{"items":[{"prompt":"Review the "config" module carefully","i":"review config"}]}' ,
144+ ) ;
145+
146+ expect ( result ) . toEqual ( {
147+ success : true ,
148+ data : { items : [ { prompt : 'Review the "config" module carefully' , i : 'review config' } ] } ,
149+ } ) ;
150+ } ) ;
151+
152+ it ( 'leaves a quote before a structural character unchanged' , ( ) => {
153+ const raw = '{"a":"done","b":1}' ;
154+
155+ expect ( parseToolCallArguments ( raw ) ) . toEqual ( { success : true , data : JSON . parse ( raw ) } ) ;
156+ } ) ;
157+
158+ it ( 'repairs invalid escapes and unescaped quotes together' , ( ) => {
159+ const result = parseToolCallArguments ( '{"a":"bold \\*x and a "quoted" word"}' ) ;
160+
161+ expect ( result ) . toEqual ( { success : true , data : { a : 'bold \\*x and a "quoted" word' } } ) ;
162+ } ) ;
163+
164+ it ( 'recognizes a string terminator separated from structure by whitespace' , ( ) => {
165+ const result = parseToolCallArguments ( '{"a":"text" , "b":"x "y" z"}' ) ;
166+
167+ expect ( result ) . toEqual ( { success : true , data : { a : 'text' , b : 'x "y" z' } } ) ;
168+ } ) ;
169+
170+ it ( 'returns the original parse error after quote repair still fails' , ( ) => {
171+ const raw = '{"a":[1,}' ;
172+ let originalError = '' ;
173+ try {
174+ JSON . parse ( raw ) ;
175+ } catch ( error ) {
176+ originalError = error instanceof Error ? error . message : String ( error ) ;
177+ }
178+
179+ expect ( parseToolCallArguments ( raw ) ) . toEqual ( { success : false , error : originalError } ) ;
180+ } ) ;
181+
141182 it ( 'returns the original parse error for structurally broken input' , ( ) => {
142183 const raw = '{"a":"truncated' ;
143184 let originalError = '' ;
0 commit comments