Skip to content

Commit 2539974

Browse files
author
Nikita Glukhov
committed
Disallow 'NOT #:' and 'NOT %:' transformation
1 parent 89f62ca commit 2539974

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

expected/jsquery.out

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2161,7 +2161,7 @@ SELECT gin_debug_query_path_value('#:(NOT x=1) AND %:(NOT y=1) AND *:(NOT z=1)')
21612161
SELECT gin_debug_query_path_value('NOT #:(NOT x=1) AND NOT %:(NOT y=1) AND NOT *:(NOT z=1)');
21622162
gin_debug_query_path_value
21632163
----------------------------
2164-
#.x = 1 , entry 0 +
2164+
NULL +
21652165

21662166
(1 row)
21672167

@@ -2370,10 +2370,7 @@ SELECT gin_debug_query_value_path('#:(NOT x=1) AND %:(NOT y=1) AND *:(NOT z=1)')
23702370
SELECT gin_debug_query_value_path('NOT #:(NOT x=1) AND NOT %:(NOT y=1) AND NOT *:(NOT z=1)');
23712371
gin_debug_query_value_path
23722372
----------------------------
2373-
AND +
2374-
#.x = 1 , entry 0 +
2375-
%.y = 1 , entry 1 +
2376-
*.z = 1 , entry 2 +
2373+
*.z = 1 , entry 0 +
23772374

23782375
(1 row)
23792376

@@ -2933,7 +2930,7 @@ select count(*) from test_jsquery where v @@ 'similar_product_ids.#: is string':
29332930
select count(*) from test_jsquery where v @@ 'NOT similar_product_ids.#: (NOT $ = "0440180295")'::jsquery;
29342931
count
29352932
-------
2936-
7
2933+
42
29372934
(1 row)
29382935

29392936
select count(*) from test_jsquery where v @@ '$ > 2'::jsquery;
@@ -3256,7 +3253,7 @@ select count(*) from test_jsquery where v @@ 'similar_product_ids.#: is string':
32563253
select count(*) from test_jsquery where v @@ 'NOT similar_product_ids.#: (NOT $ = "0440180295")'::jsquery;
32573254
count
32583255
-------
3259-
7
3256+
42
32603257
(1 row)
32613258

32623259
select count(*) from test_jsquery where v @@ '$ > 2'::jsquery;

jsquery_extract.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ recursiveExtract(JsQueryItem *jsq, bool not, bool indirect, PathItem *path)
114114
return recursiveExtract(&elem, not, indirect, pathItem);
115115
case jqiAny:
116116
case jqiAll:
117+
/* 'NOT *: (predicate)' is equivalent to '*: (NOT predicate)' */
117118
if ((not && jsq->type == jqiAny) || (!not && jsq->type == jqiAll))
118119
return NULL;
119120
pathItem = (PathItem *)palloc(sizeof(PathItem));
@@ -130,19 +131,23 @@ recursiveExtract(JsQueryItem *jsq, bool not, bool indirect, PathItem *path)
130131
if (!jsqGetNext(jsq, &elem))
131132
return makeAnyNode(not, indirect, pathItem);
132133
return recursiveExtract(&elem, not, true, pathItem);
133-
case jqiAnyArray:
134134
case jqiAllArray:
135-
if ((not && jsq->type == jqiAnyArray) || (!not && jsq->type == jqiAllArray))
135+
/* 'NOT #: (predicate)' is not equivalent to '#: (NOT predicate)' */
136+
return NULL;
137+
case jqiAnyArray:
138+
if (not)
136139
return NULL;
137140
pathItem = (PathItem *)palloc(sizeof(PathItem));
138141
pathItem->type = iAnyArray;
139142
pathItem->parent = path;
140143
if (!jsqGetNext(jsq, &elem))
141144
return makeAnyNode(not, indirect, pathItem);
142145
return recursiveExtract(&elem, not, true, pathItem);
143-
case jqiAnyKey:
144146
case jqiAllKey:
145-
if ((not && jsq->type == jqiAnyKey) || (!not && jsq->type == jqiAllKey))
147+
/* 'NOT %: (predicate)' is not equivalent to '%: (NOT predicate)' */
148+
return NULL;
149+
case jqiAnyKey:
150+
if (not)
146151
return NULL;
147152
pathItem = (PathItem *)palloc(sizeof(PathItem));
148153
pathItem->type = iAnyKey;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy