diff options
| author | Peter Eisentraut | 2022-02-16 09:32:36 +0000 |
|---|---|---|
| committer | Peter Eisentraut | 2022-02-16 09:37:31 +0000 |
| commit | 2549f0661bd28571d7200d6f82f752a7ee5d47e1 (patch) | |
| tree | 04e905d232763697d1a94cc4cc69c0154ca31372 /src/fe_utils | |
| parent | 70e81861fadd9112fa2d425c762e163910a4ee52 (diff) | |
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/fe_utils')
| -rw-r--r-- | src/fe_utils/psqlscan.l | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/src/fe_utils/psqlscan.l b/src/fe_utils/psqlscan.l index 941ed06553..ae531ec240 100644 --- a/src/fe_utils/psqlscan.l +++ b/src/fe_utils/psqlscan.l @@ -325,7 +325,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] @@ -334,10 +334,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} /* psql-specific: characters allowed in variable names */ variable_char [A-Za-z\200-\377_0-9] @@ -839,6 +843,9 @@ other . {param} { ECHO; } +{param_junk} { + ECHO; + } {integer} { ECHO; @@ -854,18 +861,16 @@ other . {real} { ECHO; } -{realfail1} { - /* - * throw back the [Ee], and figure out whether what - * remains is an {integer} or {decimal}. - * (in psql, we don't actually care...) - */ - yyless(yyleng - 1); +{realfail} { ECHO; } -{realfail2} { - /* throw back the [Ee][+-], and proceed as above */ - yyless(yyleng - 2); +{integer_junk} { + ECHO; + } +{decimal_junk} { + ECHO; + } +{real_junk} { ECHO; } |
