Skip to content

Commit f94e5bd

Browse files
committed
psql thought that backslash is an escape character inside double quotes.
It isn't.
1 parent 5bb46e7 commit f94e5bd

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/bin/psql/mainloop.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright 2000 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/mainloop.c,v 1.50 2002/09/04 20:31:36 momjian Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/mainloop.c,v 1.51 2002/10/12 23:09:34 tgl Exp $
77
*/
88
#include "postgres_fe.h"
99
#include "mainloop.h"
@@ -300,9 +300,13 @@ MainLoop(FILE *source)
300300
/* in quote? */
301301
if (in_quote)
302302
{
303-
/* end of quote */
304-
if (line[i] == in_quote && bslash_count % 2 == 0)
305-
in_quote = '\0';
303+
/*
304+
* end of quote if matching non-backslashed character.
305+
* backslashes don't count for double quotes, though.
306+
*/
307+
if (line[i] == in_quote &&
308+
(bslash_count % 2 == 0 || in_quote == '"'))
309+
in_quote = 0;
306310
}
307311

308312
/* in extended comment? */
@@ -330,12 +334,10 @@ MainLoop(FILE *source)
330334
ADVANCE_1;
331335
}
332336

333-
/* start of quote */
334-
else if (!was_bslash &&
335-
(line[i] == '\'' || line[i] == '"'))
337+
/* start of quote? */
338+
else if (line[i] == '\'' || line[i] == '"')
336339
in_quote = line[i];
337340

338-
339341
/* single-line comment? truncate line */
340342
else if (line[i] == '-' && line[i + thislen] == '-')
341343
{
@@ -446,6 +448,7 @@ MainLoop(FILE *source)
446448
/* remove the backslash */
447449
memmove(line + i - prevlen, line + i, len - i + 1);
448450
len--;
451+
i--;
449452
}
450453

451454
/* backslash command */

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