josdejong / josdejong/jsonrepair

Escaping double quote doesn't work when it is followed by slash('/') character

Open
#151 3 comments 1 reaction 0 assignees View on GitHub
enhancement help wanted
Dominant language
TypeScript
Stars
2.4k
Forks
88
PR merge metrics
No merged PRs in 30d

Description

When input string has double quote character followed by slash('/') character which is part of string value, it throws error.
Double quote without slash works fine.

Below code fails
```
const text = '{"name":"Parth","value":"This is test "message/stream"';
const parsed = jsonrepair(text);
```
with below error
```
FAIL src/index.test.ts > jsonrepair ['regular'] > repair invalid JSON > should handle missing escaping of double quotes followed by a slash
Error: Object key expected at position 39
❯ throwObjectKeyExpected src/regular/jsonrepair.ts:891:11
889|
890| function throwObjectKeyExpected() {
891| throw new JSONRepairError('Object key expected', i)
| ^
892| }
893|

FAIL src/index.test.ts > jsonrepair ['streaming'] > repair invalid JSON > should handle missing escaping of double quotes followed by a slash
Error: Unexpected character "/" at position 39
❯ throwUnexpectedCharacter src/streaming/core.ts:1023:11
1021|
1022| function throwUnexpectedCharacter() {
1023| throw new JSONRepairError(`Unexpected character ${JSON.stringify(input.charAt(i))}`, i)
| ^
1024| }
1025|
❯ parseRootEnd src/streaming/core.ts:481:7
❯ parse src/streaming/core.ts:171:20
❯ flush src/streaming/core.ts:96:12
❯ jsonrepair src/index.test.ts:774:5
❯ src/index.test.ts:695:22
```

If I remove slash after double quote it works. So below example works
```
test("should handle missing escaping of double quotes followed by a slash", () => {
const text = '{"name":"Parth","value":"This is test "message/stream"';
const parsed = jsonrepair(text);

expect(parsed).toBe(
'{"name":"Parth","value":"This is test \\"message/stream"}'
);
});
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the failing test in src/index.test.ts, then trace the reported positions in src/regular/jsonrepair.ts and src/streaming/core.ts. Check both repair paths for a missing escape before a double quote followed by a slash. Done means the test passes for regular and streaming modes and produces the expected repaired string.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.