aboutsummaryrefslogtreecommitdiff
path: root/src/backend/parser
diff options
context:
space:
mode:
authorPeter Eisentraut <peter@eisentraut.org>2022-02-16 10:32:36 +0100
committerPeter Eisentraut <peter@eisentraut.org>2022-02-16 10:37:31 +0100
commit2549f0661bd28571d7200d6f82f752a7ee5d47e1 (patch)
tree04e905d232763697d1a94cc4cc69c0154ca31372 /src/backend/parser
parent70e81861fadd9112fa2d425c762e163910a4ee52 (diff)
downloadpostgresql-2549f0661bd28571d7200d6f82f752a7ee5d47e1.tar.gz
postgresql-2549f0661bd28571d7200d6f82f752a7ee5d47e1.zip
Reject trailing junk after numeric literals
After this, the PostgreSQL lexers no longer accept numeric literals with trailing non-digits, such as 123abc, which would be scanned as two tokens: 123 and abc. This is undocumented and surprising, and it might also interfere with some extended numeric literal syntax being contemplated for the future. Reviewed-by: John Naylor <john.naylor@enterprisedb.com> Discussion: https://www.postgresql.org/message-id/flat/b239564c-cad0-b23e-c57e-166d883cb97d@enterprisedb.com
Diffstat (limited to 'src/backend/parser')
-rw-r--r--src/backend/parser/scan.l37
1 files changed, 23 insertions, 14 deletions
diff --git a/src/backend/parser/scan.l b/src/backend/parser/scan.l
index f555ac6e6d2..882e081aae2 100644
--- a/src/backend/parser/scan.l
+++ b/src/backend/parser/scan.l
@@ -387,7 +387,7 @@ operator {op_chars}+
*
* {decimalfail} is used because we would like "1..10" to lex as 1, dot_dot, 10.
*
- * {realfail1} and {realfail2} are added to prevent the need for scanner
+ * {realfail} is added to prevent the need for scanner
* backup when the {real} rule fails to match completely.
*/
digit [0-9]
@@ -396,10 +396,14 @@ integer {digit}+
decimal (({digit}*\.{digit}+)|({digit}+\.{digit}*))
decimalfail {digit}+\.\.
real ({integer}|{decimal})[Ee][-+]?{digit}+
-realfail1 ({integer}|{decimal})[Ee]
-realfail2 ({integer}|{decimal})[Ee][-+]
+realfail ({integer}|{decimal})[Ee][-+]
+
+integer_junk {integer}{ident_start}
+decimal_junk {decimal}{ident_start}
+real_junk {real}{ident_start}
param \${integer}
+param_junk \${integer}{ident_start}
other .
@@ -974,6 +978,10 @@ other .
yylval->ival = atol(yytext + 1);
return PARAM;
}
+{param_junk} {
+ SET_YYLLOC();
+ yyerror("trailing junk after parameter");
+ }
{integer} {
SET_YYLLOC();
@@ -995,20 +1003,21 @@ other .
yylval->str = pstrdup(yytext);
return FCONST;
}
-{realfail1} {
- /*
- * throw back the [Ee], and figure out whether what
- * remains is an {integer} or {decimal}.
- */
- yyless(yyleng - 1);
+{realfail} {
SET_YYLLOC();
- return process_integer_literal(yytext, yylval);
+ yyerror("trailing junk after numeric literal");
}
-{realfail2} {
- /* throw back the [Ee][+-], and proceed as above */
- yyless(yyleng - 2);
+{integer_junk} {
SET_YYLLOC();
- return process_integer_literal(yytext, yylval);
+ yyerror("trailing junk after numeric literal");
+ }
+{decimal_junk} {
+ SET_YYLLOC();
+ yyerror("trailing junk after numeric literal");
+ }
+{real_junk} {
+ SET_YYLLOC();
+ yyerror("trailing junk after numeric literal");
}