File tree Expand file tree Collapse file tree 2 files changed +12
-4
lines changed
packages/node_modules/non-blocking-json/src Expand file tree Collapse file tree 2 files changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -48,4 +48,11 @@ test("should handle more scenarios", async () => {
4848 const obj = JSON . parse ( string )
4949 const result = await stringify ( obj )
5050 expect ( result ) . toBe ( string )
51+ } )
52+
53+ test ( "should handle crazy scenario" , async ( ) => {
54+ const string = '{"foo":"\\"hey {}\\""}'
55+ const obj = JSON . parse ( string )
56+ const result = await parse ( string )
57+ expect ( result ) . toEqual ( obj )
5158} )
Original file line number Diff line number Diff line change @@ -79,7 +79,7 @@ export function stringify(value, replacer?) {
7979 }
8080
8181 for ( let [ key , value ] of paths ) {
82- if ( x % ASYNC_BATCH_COUNT === 0 ) {
82+ if ( x && x % ASYNC_BATCH_COUNT === 0 ) {
8383 if ( TRACK_PERF ) {
8484 const end = performance . now ( )
8585 console . log ( "PERF - " , end - start )
@@ -162,15 +162,16 @@ export async function parse(value) {
162162 }
163163
164164 for ( let charIndex = 0 ; charIndex < value . length ; charIndex ++ ) {
165- if ( charIndex % ASYNC_BATCH_COUNT === 0 ) {
165+ if ( charIndex && charIndex % ASYNC_BATCH_COUNT === 0 ) {
166166 if ( TRACK_PERF ) {
167167 const end = performance . now ( )
168168 console . log ( "PERF - " , end - start )
169169 start = end
170170 }
171171 await new Promise ( resolve => next ( resolve ) ) ;
172172 }
173- if ( value [ charIndex ] === '"' ) {
173+
174+ if ( value [ charIndex ] === '"' && value [ charIndex - 1 ] !== '\\' ) {
174175 isInString = ! isInString ;
175176 continue ;
176177 }
@@ -216,7 +217,7 @@ export async function parse(value) {
216217
217218 const keys = Object . keys ( parsedValue ) ;
218219
219- if ( i % ASYNC_BATCH_COUNT === 0 ) {
220+ if ( i && i % ASYNC_BATCH_COUNT === 0 ) {
220221 await new Promise ( resolve => next ( resolve ) ) ;
221222 }
222223
You can’t perform that action at this time.
0 commit comments