Skip to content

Commit 3ea7e01

Browse files
committed
Fix pgbench lexer's "continuation" rule to cope with Windows newlines.
Our general practice in frontend code is to accept input with either Unix-style newlines (\n) or DOS-style (\r\n). pgbench was mostly down with that, but its rule for line continuations (backslash-newline) was not. This had been masked on Windows buildfarm machines before commit 0ba06e0 by use of Windows text mode to read files. We could have fixed it by forcing text mode again, but it's better to fix the parsing code so that Windows-style text files on Unix systems don't cause problems. Back-patch to v10 where pgbench grew line continuations. Discussion: https://postgr.es/m/17194.1537191697@sss.pgh.pa.us
1 parent c374017 commit 3ea7e01

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/bin/pgbench/exprscan.l

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ nonspace [^ \t\r\f\v\n]
6767
newline [\n]
6868

6969
/* Line continuation marker */
70-
continuation \\{newline}
70+
continuation \\\r?{newline}
7171

7272
/* Exclusive states */
7373
%x EXPR
@@ -104,8 +104,12 @@ continuation \\{newline}
104104
* a continuation marker just after a word:
105105
*/
106106
{nonspace}+{continuation} {
107-
/* Found "word\\\n", emit and return just "word" */
108-
psqlscan_emit(cur_state, yytext, yyleng - 2);
107+
/* Found "word\\\r?\n", emit and return just "word" */
108+
int wordlen = yyleng - 2;
109+
if (yytext[wordlen] == '\r')
110+
wordlen--;
111+
Assert(yytext[wordlen] == '\\');
112+
psqlscan_emit(cur_state, yytext, wordlen);
109113
return 1;
110114
}
111115

0 commit comments

Comments
 (0)