Skip to content

Enhance the escaping flow #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,13 @@ private void handleClosedBracket(char currentChar, int position) {

private void handleCommaToFixMissingClosedQuote(char currentChar, int position) {
char nextNonSpaceChar = findNextNonSpaceChar(position + 1);
int nextNonSpaceCharPosition = getNextNonSpaceCharPosition(position + 1);
if (nextNonSpaceChar == DOUBLE_QUOTE_CHAR ) {
// We MUST ignore adding close quote if the next quote is a good close quote
if(isValidCloseQuoteAtPosition(nextNonSpaceCharPosition)) {
escapedJson.append(currentChar);
return;
}
escapedJson.append(DOUBLE_QUOTE_CHAR);
inQuotes = false;
}
Expand Down
17 changes: 15 additions & 2 deletions src/test/java/com/cdpn/jsonautorepair/JSONAutoRepairerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,21 @@ public void repair_should_fix_missing_end_quote_of_value() {
"""));
}



@Test
public void repair_should_treat_the_comma_before_a_good_close_quote_as_other_characters() {
String originalJSON = """
{
"type": "5,
"hits": [
{
"hitText": "hello,",
"index": "2"
}
]
}```
""";
assertNotNull(jsonAutoRepairer.repair(originalJSON));
}
@Test
public void repair_should_return_good_JSON_string_output_when_the_string_is_a_valid_JSON() {
String originalJSON = """
Expand Down
Loading