Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit f3fd502

Browse files
author
Nikita Glukhov
committed
Add STRICT/LAX jsonpath mode
1 parent d494e65 commit f3fd502

File tree

11 files changed

+522
-122
lines changed

11 files changed

+522
-122
lines changed

src/backend/utils/adt/jsonpath.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ jsonpath_in(PG_FUNCTION_ARGS)
179179
{
180180
char *in = PG_GETARG_CSTRING(0);
181181
int32 len = strlen(in);
182-
JsonPathParseItem *jsonpath = parsejsonpath(in, len);
183-
JsonPath *res;
182+
JsonPathParseResult *jsonpath = parsejsonpath(in, len);
183+
JsonPath *res;
184184
StringInfoData buf;
185185

186186
initStringInfo(&buf);
@@ -193,11 +193,13 @@ jsonpath_in(PG_FUNCTION_ARGS)
193193
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
194194
errmsg("invalid input syntax for jsonpath: \"%s\"", in)));
195195

196-
flattenJsonPathParseItem(&buf, jsonpath, false);
196+
flattenJsonPathParseItem(&buf, jsonpath->expr, false);
197197

198198
res = (JsonPath*)buf.data;
199199
SET_VARSIZE(res, buf.len);
200200
res->header = JSONPATH_VERSION;
201+
if (jsonpath->lax)
202+
res->header |= JSONPATH_LAX;
201203

202204
PG_RETURN_JSONPATH_P(res);
203205
}
@@ -414,6 +416,9 @@ jsonpath_out(PG_FUNCTION_ARGS)
414416
initStringInfo(&buf);
415417
enlargeStringInfo(&buf, VARSIZE(in) /* estimation */);
416418

419+
if (!(in->header & JSONPATH_LAX))
420+
appendBinaryStringInfo(&buf, "strict ", 7);
421+
417422
jspInit(&v, in);
418423
printJsonPathItem(&buf, &v, false, true);
419424

@@ -447,7 +452,7 @@ jsonpath_out(PG_FUNCTION_ARGS)
447452
void
448453
jspInit(JsonPathItem *v, JsonPath *js)
449454
{
450-
Assert(js->header == JSONPATH_VERSION);
455+
Assert((js->header & ~JSONPATH_LAX) == JSONPATH_VERSION);
451456
jspInitByBuffer(v, js->data, 0);
452457
}
453458

0 commit comments

Comments
 (0)