diff options
author | Andrew Dunstan <andrew@dunslane.net> | 2025-01-19 09:09:58 -0500 |
---|---|---|
committer | Andrew Dunstan <andrew@dunslane.net> | 2025-01-19 09:09:58 -0500 |
commit | ea5ff5833c7d4ae727a5acfc590c848b520775d0 (patch) | |
tree | 8c08c15dfcccd02c2286bb9f5dd951783c96e2ab /src/common/jsonapi.c | |
parent | d3d0983169130a9b81e3fe48d5c2ca4931480956 (diff) | |
download | postgresql-ea5ff5833c7d4ae727a5acfc590c848b520775d0.tar.gz postgresql-ea5ff5833c7d4ae727a5acfc590c848b520775d0.zip |
Be clearer about when jsonapi's need_escapes is needed
Most operations beyond pure json parsing need to set need_escapes to
true to get access to field names and string scalars. Document this
fact more explicitly.
Slightly tweaked patch from:
Author: Corey Huinker <corey.huinker@gmail.com>
Discussion: https://postgr.es/m/CADkLM=c49Vkfg2+A8ubSuEtaGEjuaKZXCA6SrXA8kdwHjx3uxQ@mail.gmail.com
Diffstat (limited to 'src/common/jsonapi.c')
-rw-r--r-- | src/common/jsonapi.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/common/jsonapi.c b/src/common/jsonapi.c index 1069e8c5b3f..f1c80933c92 100644 --- a/src/common/jsonapi.c +++ b/src/common/jsonapi.c @@ -1297,7 +1297,10 @@ parse_scalar(JsonLexContext *lex, const JsonSemAction *sem) return result; } - /* invoke the callback, which may take ownership of val */ + /* + * invoke the callback, which may take ownership of val. For string + * values, val is NULL if need_escapes is false. + */ result = (*sfunc) (sem->semstate, val, tok); if (lex->flags & JSONLEX_CTX_OWNS_TOKENS) @@ -1326,6 +1329,7 @@ parse_object_field(JsonLexContext *lex, const JsonSemAction *sem) return report_parse_error(JSON_PARSE_STRING, lex); if ((ostart != NULL || oend != NULL) && lex->need_escapes) { + /* fname is NULL if need_escapes is false */ fname = STRDUP(lex->strval->data); if (fname == NULL) return JSON_OUT_OF_MEMORY; |