File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed
main/java/com/endava/cats/util
test/java/com/endava/cats/util Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -54,7 +54,7 @@ private static String formatJsonString(String jsonStr) {
5454 }
5555 case '}' , ']' -> {
5656 if (prevChar != '{' && prevChar != '[' && prevChar != '\n' ) {
57- formatted .append ('\n' ).append (indent .repeat (indentLevel - 1 ));
57+ formatted .append ('\n' ).append (indent .repeat (Math . max ( 0 , indentLevel - 1 ) ));
5858 }
5959 indentLevel --;
6060 formatted .append (currentChar );
Original file line number Diff line number Diff line change @@ -44,4 +44,27 @@ void shouldHandleEscapedQuotesInJsonString() {
4444 String result = SimpleJsonFormatter .formatJson (input );
4545 assertThat (result ).isEqualTo (expected );
4646 }
47+
48+ @ Test
49+ void shouldHandleMalformedJsonWithExtraClosingBrackets () {
50+ String input = "{\" key\" :\" value\" }}" ;
51+ String result = SimpleJsonFormatter .formatJson (input );
52+ assertThat (result ).isNotNull ();
53+ }
54+
55+ @ Test
56+ void shouldHandleMalformedJsonWithExtraClosingSquareBrackets () {
57+ String input = "[1,2,3]]" ;
58+ String result = SimpleJsonFormatter .formatJson (input );
59+ assertThat (result ).isNotNull ();
60+ }
61+
62+ @ Test
63+ void shouldHandleNestedStructures () {
64+ String input = "{\" outer\" :{\" inner\" :{\" deep\" :\" value\" }}}" ;
65+ String result = SimpleJsonFormatter .formatJson (input );
66+ assertThat (result ).contains ("\" outer\" :" );
67+ assertThat (result ).contains ("\" inner\" :" );
68+ assertThat (result ).contains ("\" deep\" : \" value\" " );
69+ }
4770}
You can’t perform that action at this time.
0 commit comments