From 61c224f4f73c149c52b2ca21d323554c55b3b37e Mon Sep 17 00:00:00 2001 From: Eibz-Chan Date: Mon, 7 Nov 2022 11:16:28 +0800 Subject: [PATCH] reason: add backport-When-serializing-with-JSON_C_TO_STRING_PRETTY-set-ke.patch type: bugfix --- ...-with-JSON_C_TO_STRING_PRETTY-set-ke.patch | 202 ++++++++++++++++++ json-c.spec | 6 +- 2 files changed, 207 insertions(+), 1 deletion(-) create mode 100644 backport-When-serializing-with-JSON_C_TO_STRING_PRETTY-set-ke.patch diff --git a/backport-When-serializing-with-JSON_C_TO_STRING_PRETTY-set-ke.patch b/backport-When-serializing-with-JSON_C_TO_STRING_PRETTY-set-ke.patch new file mode 100644 index 0000000..1cc547b --- /dev/null +++ b/backport-When-serializing-with-JSON_C_TO_STRING_PRETTY-set-ke.patch @@ -0,0 +1,202 @@ +From 9749b0cb66b32ddac4bbbca28dd9009968722a9f Mon Sep 17 00:00:00 2001 +From: Eric Haszlakiewicz +Date: Sat, 30 Jul 2022 19:27:14 +0000 +Subject: [PATCH] When serializing with JSON_C_TO_STRING_PRETTY set, keep the + opening and closing curly or square braces on same line for empty objects or + arrays. Issue #778. + +--- + ChangeLog | 17 ++++++++++++++ + json_object.c | 22 +++++++------------ + tests/test1.c | 5 +++++ + tests/test1.expected | 2 +- + tests/test1Formatted_plain.expected | 2 +- + tests/test1Formatted_pretty.expected | 4 +++- + tests/test1Formatted_spaced.expected | 2 +- + tests/test1Formatted_spaced_pretty.expected | 4 +++- + ...ormatted_spaced_pretty_pretty_tab.expected | 4 +++- + 9 files changed, 42 insertions(+), 20 deletions(-) + +diff --git a/ChangeLog b/ChangeLog +index b03a777..8cadae6 100644 +--- a/ChangeLog ++++ b/ChangeLog +@@ -1,4 +1,21 @@ + ++0.17 (future release) ++======================================== ++ ++Deprecated and removed features: ++-------------------------------- ++* ... ++ ++New features ++------------ ++* ... ++ ++Significant changes and bug fixes ++--------------------------------- ++* When serializing with JSON_C_TO_STRING_PRETTY set, keep the opening and ++ closing curly or square braces on same line for empty objects or arrays. ++ ++ + 0.16 (up to commit 66dcdf5, 2022-04-13) + ======================================== + +diff --git a/json_object.c b/json_object.c +index 581b1e2..14cd594 100644 +--- a/json_object.c ++++ b/json_object.c +@@ -460,16 +460,14 @@ static int json_object_object_to_json_string(struct json_object *jso, struct pri + struct json_object_iter iter; + + printbuf_strappend(pb, "{" /*}*/); +- if (flags & JSON_C_TO_STRING_PRETTY) +- printbuf_strappend(pb, "\n"); + json_object_object_foreachC(jso, iter) + { + if (had_children) + { + printbuf_strappend(pb, ","); +- if (flags & JSON_C_TO_STRING_PRETTY) +- printbuf_strappend(pb, "\n"); + } ++ if (flags & JSON_C_TO_STRING_PRETTY) ++ printbuf_strappend(pb, "\n"); + had_children = 1; + if (flags & JSON_C_TO_STRING_SPACED && !(flags & JSON_C_TO_STRING_PRETTY)) + printbuf_strappend(pb, " "); +@@ -485,10 +483,9 @@ static int json_object_object_to_json_string(struct json_object *jso, struct pri + else if (iter.val->_to_json_string(iter.val, pb, level + 1, flags) < 0) + return -1; + } +- if (flags & JSON_C_TO_STRING_PRETTY) ++ if ((flags & JSON_C_TO_STRING_PRETTY) && had_children) + { +- if (had_children) +- printbuf_strappend(pb, "\n"); ++ printbuf_strappend(pb, "\n"); + indent(pb, level, flags); + } + if (flags & JSON_C_TO_STRING_SPACED && !(flags & JSON_C_TO_STRING_PRETTY)) +@@ -1381,17 +1378,15 @@ static int json_object_array_to_json_string(struct json_object *jso, struct prin + size_t ii; + + printbuf_strappend(pb, "["); +- if (flags & JSON_C_TO_STRING_PRETTY) +- printbuf_strappend(pb, "\n"); + for (ii = 0; ii < json_object_array_length(jso); ii++) + { + struct json_object *val; + if (had_children) + { + printbuf_strappend(pb, ","); +- if (flags & JSON_C_TO_STRING_PRETTY) +- printbuf_strappend(pb, "\n"); + } ++ if (flags & JSON_C_TO_STRING_PRETTY) ++ printbuf_strappend(pb, "\n"); + had_children = 1; + if (flags & JSON_C_TO_STRING_SPACED && !(flags & JSON_C_TO_STRING_PRETTY)) + printbuf_strappend(pb, " "); +@@ -1402,10 +1397,9 @@ static int json_object_array_to_json_string(struct json_object *jso, struct prin + else if (val->_to_json_string(val, pb, level + 1, flags) < 0) + return -1; + } +- if (flags & JSON_C_TO_STRING_PRETTY) ++ if ((flags & JSON_C_TO_STRING_PRETTY) && had_children) + { +- if (had_children) +- printbuf_strappend(pb, "\n"); ++ printbuf_strappend(pb, "\n"); + indent(pb, level, flags); + } + +diff --git a/tests/test1.c b/tests/test1.c +index 01796ab..befd246 100644 +--- a/tests/test1.c ++++ b/tests/test1.c +@@ -311,6 +311,11 @@ int main(int argc, char **argv) + { + printf("\t%s: %s\n", key, json_object_to_json_string(val)); + } ++ ++ json_object *empty_array = json_object_new_array(); ++ json_object *empty_obj = json_object_new_object(); ++ json_object_object_add(my_object, "empty_array", empty_array); ++ json_object_object_add(my_object, "empty_obj", empty_obj); + printf("my_object.to_string()=%s\n", json_object_to_json_string(my_object)); + + json_object_put(my_array); +diff --git a/tests/test1.expected b/tests/test1.expected +index 4b6b252..b473a8b 100644 +--- a/tests/test1.expected ++++ b/tests/test1.expected +@@ -75,4 +75,4 @@ my_object= + foo: "bar" + bool0: false + bool1: true +-my_object.to_string()={ "abc": 12, "foo": "bar", "bool0": false, "bool1": true } ++my_object.to_string()={ "abc": 12, "foo": "bar", "bool0": false, "bool1": true, "empty_array": [ ], "empty_obj": { } } +diff --git a/tests/test1Formatted_plain.expected b/tests/test1Formatted_plain.expected +index 128e274..ad12d99 100644 +--- a/tests/test1Formatted_plain.expected ++++ b/tests/test1Formatted_plain.expected +@@ -75,4 +75,4 @@ my_object= + foo: "bar" + bool0: false + bool1: true +-my_object.to_string()={"abc":12,"foo":"bar","bool0":false,"bool1":true} ++my_object.to_string()={"abc":12,"foo":"bar","bool0":false,"bool1":true,"empty_array":[],"empty_obj":{}} +diff --git a/tests/test1Formatted_pretty.expected b/tests/test1Formatted_pretty.expected +index b67185f..ab2cc78 100644 +--- a/tests/test1Formatted_pretty.expected ++++ b/tests/test1Formatted_pretty.expected +@@ -97,5 +97,7 @@ my_object.to_string()={ + "abc":12, + "foo":"bar", + "bool0":false, +- "bool1":true ++ "bool1":true, ++ "empty_array":[], ++ "empty_obj":{} + } +diff --git a/tests/test1Formatted_spaced.expected b/tests/test1Formatted_spaced.expected +index fe6979d..f57bd05 100644 +--- a/tests/test1Formatted_spaced.expected ++++ b/tests/test1Formatted_spaced.expected +@@ -75,4 +75,4 @@ my_object= + foo: "bar" + bool0: false + bool1: true +-my_object.to_string()={ "abc": 12, "foo": "bar", "bool0": false, "bool1": true } ++my_object.to_string()={ "abc": 12, "foo": "bar", "bool0": false, "bool1": true, "empty_array": [ ], "empty_obj": { } } +diff --git a/tests/test1Formatted_spaced_pretty.expected b/tests/test1Formatted_spaced_pretty.expected +index 104a554..c88729f 100644 +--- a/tests/test1Formatted_spaced_pretty.expected ++++ b/tests/test1Formatted_spaced_pretty.expected +@@ -97,5 +97,7 @@ my_object.to_string()={ + "abc": 12, + "foo": "bar", + "bool0": false, +- "bool1": true ++ "bool1": true, ++ "empty_array": [], ++ "empty_obj": {} + } +diff --git a/tests/test1Formatted_spaced_pretty_pretty_tab.expected b/tests/test1Formatted_spaced_pretty_pretty_tab.expected +index f9a8e87..bab239f 100644 +--- a/tests/test1Formatted_spaced_pretty_pretty_tab.expected ++++ b/tests/test1Formatted_spaced_pretty_pretty_tab.expected +@@ -97,5 +97,7 @@ my_object.to_string()={ + "abc": 12, + "foo": "bar", + "bool0": false, +- "bool1": true ++ "bool1": true, ++ "empty_array": [], ++ "empty_obj": {} + } +-- +2.27.0 + diff --git a/json-c.spec b/json-c.spec index c85b7b6..752c5c3 100644 --- a/json-c.spec +++ b/json-c.spec @@ -6,7 +6,7 @@ Name: json-c Version: 0.15 -Release: 5 +Release: 6 Summary: JSON implementation in C License: MIT @@ -28,6 +28,7 @@ Summary: Development files for %{name} Requires: %{name}%{?_isa} == %{version}-%{release} Patch6001: backport-json-escape-str-avoid-harmless-unsigned-integer-overflow.patch +Patch6002: backport-When-serializing-with-JSON_C_TO_STRING_PRETTY-set-ke.patch %description devel This package contains libraries and header files for @@ -105,6 +106,9 @@ end %doc %{_pkgdocdir} %changelog +* Mon Nov 7 2022 Eibz-Chan - 0.15-6 +- Fix When-serializing-with-JSON_C_TO_STRING_PRETTY-set-ke + * Tue May 24 2022 fengtao - 0.15-5 - we got upgrade error when upgrade json-c from very low version, for example json-c-0.11-5. because old version has a softlink: -- Gitee