Skip to content

Commit 35d8940

Browse files
committed
Fix up some oversights in psql's Unicode-escape support.
Original patch failed to include new exclusive states in a switch that needed to include them; and also was guilty of very fuzzy thinking about how to handle error cases. Per bug #5729 from Alan Choi.
1 parent 5a12c80 commit 35d8940

File tree

1 file changed

+17
-22
lines changed

1 file changed

+17
-22
lines changed

src/bin/psql/psqlscan.l

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ static bool var_is_current_source(PsqlScanState state, const char *varname);
120120
static YY_BUFFER_STATE prepare_buffer(const char *txt, int len,
121121
char **txtcopy);
122122
static void emit(const char *txt, int len);
123-
static bool is_utf16_surrogate_first(uint32 c);
124123
static void escape_variable(bool as_ident);
125124

126125
#define ECHO emit(yytext, yyleng)
@@ -163,7 +162,11 @@ static void escape_variable(bool as_ident);
163162
* <xdolq> $foo$ quoted strings
164163
* <xui> quoted identifier with Unicode escapes
165164
* <xus> quoted string with Unicode escapes
166-
* <xeu> Unicode surrogate pair in extended quoted string
165+
*
166+
* Note: we intentionally don't mimic the backend's <xeu> state; we have
167+
* no need to distinguish it from <xe> state, and no good way to get out
168+
* of it in error cases. The backend just throws yyerror() in those
169+
* cases, but that's not an option here.
167170
*/
168171

169172
%x xb
@@ -175,7 +178,6 @@ static void escape_variable(bool as_ident);
175178
%x xdolq
176179
%x xui
177180
%x xus
178-
%x xeu
179181
/* Additional exclusive states for psql only: lex backslash commands */
180182
%x xslashcmd
181183
%x xslasharg
@@ -529,19 +531,9 @@ other .
529531
ECHO;
530532
}
531533
<xe>{xeunicode} {
532-
uint32 c = strtoul(yytext+2, NULL, 16);
533-
534-
if (is_utf16_surrogate_first(c))
535-
BEGIN(xeu);
536-
ECHO;
537-
}
538-
<xeu>{xeunicode} {
539-
BEGIN(xe);
540534
ECHO;
541535
}
542-
<xeu>. { ECHO; }
543-
<xeu>\n { ECHO; }
544-
<xe,xeu>{xeunicodefail} {
536+
<xe>{xeunicodefail} {
545537
ECHO;
546538
}
547539
<xe>{xeescape} {
@@ -1242,6 +1234,7 @@ psql_scan(PsqlScanState state,
12421234
case LEXRES_EOL: /* end of input */
12431235
switch (state->start_state)
12441236
{
1237+
/* This switch must cover all non-slash-command states. */
12451238
case INITIAL:
12461239
if (state->paren_depth > 0)
12471240
{
@@ -1276,18 +1269,26 @@ psql_scan(PsqlScanState state,
12761269
result = PSCAN_INCOMPLETE;
12771270
*prompt = PROMPT_SINGLEQUOTE;
12781271
break;
1279-
case xq:
1272+
case xe:
12801273
result = PSCAN_INCOMPLETE;
12811274
*prompt = PROMPT_SINGLEQUOTE;
12821275
break;
1283-
case xe:
1276+
case xq:
12841277
result = PSCAN_INCOMPLETE;
12851278
*prompt = PROMPT_SINGLEQUOTE;
12861279
break;
12871280
case xdolq:
12881281
result = PSCAN_INCOMPLETE;
12891282
*prompt = PROMPT_DOLLARQUOTE;
12901283
break;
1284+
case xui:
1285+
result = PSCAN_INCOMPLETE;
1286+
*prompt = PROMPT_DOUBLEQUOTE;
1287+
break;
1288+
case xus:
1289+
result = PSCAN_INCOMPLETE;
1290+
*prompt = PROMPT_SINGLEQUOTE;
1291+
break;
12911292
default:
12921293
/* can't get here */
12931294
fprintf(stderr, "invalid YY_START\n");
@@ -1814,12 +1815,6 @@ emit(const char *txt, int len)
18141815
}
18151816
}
18161817

1817-
static bool
1818-
is_utf16_surrogate_first(uint32 c)
1819-
{
1820-
return (c >= 0xD800 && c <= 0xDBFF);
1821-
}
1822-
18231818
static void
18241819
escape_variable(bool as_ident)
18251820
{

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