Commit aad35a3
fix: infinite loop when object has an empty string key (#58)
The key-advance logic in `diffObject` used falsy checks (!keyLeft,
!keyRight) to detect when one side had run out of keys. Because an
empty string is falsy in JavaScript, any JSON object containing "" as
a key would cause the left pointer to never advance, producing an
infinite while-loop that exhausted all available memory.
Fix: replace the falsy checks with strict undefined comparisons
(=== undefined) so that empty-string keys are handled correctly.
A regression test is added to differ.spec.ts covering objects with
an empty-string key on both sides.
Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>1 parent ab5529e commit aad35a3
2 files changed
Lines changed: 18 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
4 | 20 | | |
5 | 21 | | |
6 | 22 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
181 | 181 | | |
182 | 182 | | |
183 | 183 | | |
184 | | - | |
| 184 | + | |
185 | 185 | | |
186 | | - | |
| 186 | + | |
187 | 187 | | |
188 | 188 | | |
189 | 189 | | |
| |||
0 commit comments