Skip to content

[PGPRO-9047] Fixed parsing empty string into NULL #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions expected/jsquery.out
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ set escape_string_warning=off;
set standard_conforming_strings=on;
CREATE TABLE test_jsquery (v jsonb);
\copy test_jsquery from 'data/test_jsquery.data'
select ''::jsquery;
ERROR: bad jsquery representation
LINE 1: select ''::jsquery;
^
DETAIL: No symbols read at the end of input
select 'asd.zzz = 13'::jsquery;
jsquery
------------------
Expand Down
5 changes: 5 additions & 0 deletions expected/jsquery_1.out
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ set escape_string_warning=off;
set standard_conforming_strings=on;
CREATE TABLE test_jsquery (v jsonb);
\copy test_jsquery from 'data/test_jsquery.data'
select ''::jsquery;
ERROR: bad jsquery representation
LINE 1: select ''::jsquery;
^
DETAIL: No symbols read at the end of input
select 'asd.zzz = 13'::jsquery;
jsquery
------------------
Expand Down
4 changes: 3 additions & 1 deletion jsquery_gram.y
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,9 @@ result:
*result = $1;
(void) yynerrs; /* suppress compiler warning */
}
| /* EMPTY */ { *result = NULL; }
| /* EMPTY */ {
*result = NULL;
yyerror(NULL, "No symbols read"); }
;

array:
Expand Down
13 changes: 4 additions & 9 deletions jsquery_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,17 +162,12 @@ jsquery_in(PG_FUNCTION_ARGS)

appendStringInfoSpaces(&buf, VARHDRSZ);

if (jsquery != NULL)
{
flattenJsQueryParseItem(&buf, jsquery, false);

res = (JsQuery*)buf.data;
SET_VARSIZE(res, buf.len);
flattenJsQueryParseItem(&buf, jsquery, false);

PG_RETURN_JSQUERY(res);
}
res = (JsQuery*)buf.data;
SET_VARSIZE(res, buf.len);

PG_RETURN_NULL();
PG_RETURN_JSQUERY(res);
}

static void
Expand Down
2 changes: 1 addition & 1 deletion jsquery_scan.l
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ yyerror(JsQueryParseItem **result, const char *message)
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("bad jsquery representation"),
/* translator: %s is typically "syntax error" */
errdetail("%s at end of input", message)));
errdetail("%s at the end of input", message)));
}
else
{
Expand Down
1 change: 1 addition & 0 deletions sql/jsquery.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ CREATE TABLE test_jsquery (v jsonb);

\copy test_jsquery from 'data/test_jsquery.data'

select ''::jsquery;
select 'asd.zzz = 13'::jsquery;
select 'asd.zzz < 13'::jsquery;
select 'asd(zzz < 13)'::jsquery;
Expand Down