From 2787c048065b2330eecf765cc567873cba93d800 Mon Sep 17 00:00:00 2001 From: vancekic Date: Wed, 5 Aug 2015 23:19:14 -0400 Subject: [PATCH 1/3] Fixing issue #2: notepad++ was hanging. Now the correct json is formatted properly. --- NppJSONViewer/json.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/NppJSONViewer/json.c b/NppJSONViewer/json.c index a282ba5..f46439c 100755 --- a/NppJSONViewer/json.c +++ b/NppJSONViewer/json.c @@ -1101,11 +1101,6 @@ json_format_string (const char *text) { rcs_catc (output, '\\'); pos++; - if (text[pos] == '\"') /* don't consider a \" escaped sequence as an end of string */ - { - rcs_catc (output, '\"'); - pos++; - } } else if (text[pos] == '\"') /* reached end of string */ { From cb1d0ca8223763821e239d63844957863bbca976 Mon Sep 17 00:00:00 2001 From: vancekic Date: Thu, 6 Aug 2015 18:37:53 -0400 Subject: [PATCH 2/3] fix hangup when json is closing more } than there are { --- NppJSONViewer/json.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/NppJSONViewer/json.c b/NppJSONViewer/json.c index f46439c..b5f3ba2 100755 --- a/NppJSONViewer/json.c +++ b/NppJSONViewer/json.c @@ -1037,8 +1037,11 @@ char * json_format_string (const char *text) { size_t pos = 0, text_length; - unsigned int indentation = 0; /* the current indentation level */ - unsigned int i; /* loop iterator variable */ + + // make sure these two integers are signed + // we want to allow negative when the json is bad + signed int indentation = 0; /* the current indentation level */ + signed int i; /* loop iterator variable */ char loop; rcstring *output; @@ -1069,6 +1072,9 @@ json_format_string (const char *text) case '}': indentation--; rcs_catc (output, '\n'); + // the for loop will compare i with potential negative values + // so we don't get caught in an infinite loop if the json is faulty with more "}" than "{" + // we just print out the same number of faulty "}" characters. for (i = 0; i < indentation; i++) { rcs_catc (output, '\t'); From 99992c55e2cf68f88b911833af14246a2444b37d Mon Sep 17 00:00:00 2001 From: vancekic Date: Thu, 6 Aug 2015 18:40:29 -0400 Subject: [PATCH 3/3] better comments --- NppJSONViewer/json.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NppJSONViewer/json.c b/NppJSONViewer/json.c index b5f3ba2..0fc7153 100755 --- a/NppJSONViewer/json.c +++ b/NppJSONViewer/json.c @@ -1039,7 +1039,7 @@ json_format_string (const char *text) size_t pos = 0, text_length; // make sure these two integers are signed - // we want to allow negative when the json is bad + // we want to allow testing against negative when the json is bad signed int indentation = 0; /* the current indentation level */ signed int i; /* loop iterator variable */ char loop;