Commit 9111d463 authored by Andrew Dunstan's avatar Andrew Dunstan

Remove ill-conceived ban on zero length json object keys.

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.
parent 5d7962c6
...@@ -1342,6 +1342,9 @@ datum_to_json(Datum val, bool is_null, StringInfo result, ...@@ -1342,6 +1342,9 @@ datum_to_json(Datum val, bool is_null, StringInfo result,
bool numeric_error; bool numeric_error;
JsonLexContext dummy_lex; JsonLexContext dummy_lex;
/* callers are expected to ensure that null keys are not passed in */
Assert( ! (key_scalar && is_null));
if (is_null) if (is_null)
{ {
appendStringInfoString(result, "null"); appendStringInfoString(result, "null");
...@@ -1487,10 +1490,6 @@ datum_to_json(Datum val, bool is_null, StringInfo result, ...@@ -1487,10 +1490,6 @@ datum_to_json(Datum val, bool is_null, StringInfo result,
break; break;
default: default:
outputstr = OidOutputFunctionCall(outfuncoid, val); 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); escape_json(result, outputstr);
pfree(outputstr); pfree(outputstr);
break; break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment