Skip to content

Commit 53ad0aa

Browse files
author
Thomas G. Lockhart
committed
Restore proper behavior for escaped quotes and for escaped literals
like newline inside quoted strings.
1 parent c7dbd36 commit 53ad0aa

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

src/backend/parser/scan.l

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/parser/scan.l,v 1.21 1997/09/13 03:12:55 thomas Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/parser/scan.l,v 1.22 1997/09/24 17:48:25 thomas Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -91,8 +91,9 @@ quote '
9191
xqstart {quote}
9292
xqstop {quote}
9393
xqdouble {quote}{quote}
94-
xqinside [^\']*
95-
xqliteral [\\].
94+
xqinside [^\\']*
95+
xqembedded "\\'"
96+
xqliteral [\\](.|\n)
9697

9798
xcline [\/][\*].*[\*][\/]{space}*\n*
9899
xcstart [\/][\*]{op_and_self}*
@@ -132,6 +133,14 @@ other .
132133
/* DO NOT PUT ANY COMMENTS IN THE FOLLOWING SECTION.
133134
* AT&T lex does not properly handle C-style comments in this second lex block.
134135
* So, put comments here. tgl - 1997-09-08
136+
*
137+
* Quoted strings must allow some special characters such as single-quote
138+
* and newline.
139+
* Embedded single-quotes are implemented both in the SQL/92-standard
140+
* style of two adjacent single quotes "''" and in the Postgres/Java style
141+
* of escaped-quote "\'".
142+
* Other embedded escaped characters are matched explicitly and the leading
143+
* backslash is dropped from the string. - thomas 1997-09-24
135144
*/
136145

137146
%%
@@ -163,6 +172,14 @@ other .
163172
memcpy(literal+llen, yytext, yyleng+1);
164173
llen += yyleng;
165174
}
175+
<xq>{xqembedded} {
176+
if ((llen+yyleng-1) > (MAX_PARSE_BUFFER - 1))
177+
elog(WARN,"quoted string parse buffer of %d chars exceeded",MAX_PARSE_BUFFER);
178+
memcpy(literal+llen, yytext, yyleng+1);
179+
*(literal+llen) = '\'';
180+
llen += yyleng;
181+
}
182+
166183
<xq>{xqliteral} {
167184
if ((llen+yyleng-1) > (MAX_PARSE_BUFFER - 1))
168185
elog(WARN,"quoted string parse buffer of %d chars exceeded",MAX_PARSE_BUFFER);

0 commit comments

Comments
 (0)