]> granicus.if.org Git - postgresql/commitdiff
Remove ill-conceived ban on zero length json object keys.
authorAndrew Dunstan <andrew@dunslane.net>
Thu, 25 Sep 2014 19:08:42 +0000 (15:08 -0400)
committerAndrew Dunstan <andrew@dunslane.net>
Thu, 25 Sep 2014 19:12:44 +0000 (15:12 -0400)
We removed a similar ban on this in json_object recently, but the ban in
datum_to_json was left, which generate4d sprutious errors in othee json
generators, notable json_build_object.

Along the way, add an assertion that datum_to_json is not passed a null
key. All current callers comply with this rule, but the assertion will
catch any possible future misbehaviour.

src/backend/utils/adt/json.c

index 1820029fe956d68d28678826dfc0d33097245660..d2bf640e54e72541591434d0ffa8a29411d32948 100644 (file)
@@ -1341,6 +1341,9 @@ datum_to_json(Datum val, bool is_null, StringInfo result,
        bool            numeric_error;
        JsonLexContext dummy_lex;
 
+       /* callers are expected to ensure that null keys are not passed in */
+       Assert( ! (key_scalar && is_null));
+
        if (is_null)
        {
                appendStringInfoString(result, "null");
@@ -1486,10 +1489,6 @@ datum_to_json(Datum val, bool is_null, StringInfo result,
                        break;
                default:
                        outputstr = OidOutputFunctionCall(outfuncoid, val);
-                       if (key_scalar && *outputstr == '\0')
-                               ereport(ERROR,
-                                               (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-                                                errmsg("key value must not be empty")));
                        escape_json(result, outputstr);
                        pfree(outputstr);
                        break;