Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 18cbc7a

Browse files
committed
Use 0x01 for newlines in saved history. It was determined to be not
used by multi-byte sequences, but futher invesetigation might prove this to be false.
1 parent f7d9874 commit 18cbc7a

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/bin/psql/input.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/input.c,v 1.47 2006/02/11 21:55:35 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/input.c,v 1.48 2006/02/12 05:24:38 momjian Exp $
77
*/
88
#include "postgres_fe.h"
99

@@ -26,6 +26,15 @@ static bool useReadline;
2626
static bool useHistory;
2727
char *psql_history;
2828

29+
/*
30+
* Preserve newlines in saved queries by mapping '\n' to NL_IN_HISTORY
31+
*
32+
* It is assumed NL_IN_HISTORY will never be entered by the user
33+
* nor appear inside a multi-byte string. 0x00 is not properly
34+
* handled by the readline routines so it can not be used
35+
* for this purpose.
36+
*/
37+
#define NL_IN_HISTORY 0x01
2938

3039
enum histcontrol
3140
{
@@ -213,7 +222,7 @@ static void encode_history()
213222
cur_hist; cur_hist = next_history())
214223
for (cur_ptr = cur_hist->line; *cur_ptr; cur_ptr++)
215224
if (*cur_ptr == '\n')
216-
*cur_ptr = '\0';
225+
*cur_ptr = NL_IN_HISTORY;
217226
}
218227

219228
static void decode_history()
@@ -224,7 +233,7 @@ static void decode_history()
224233
for (history_set_pos(0), cur_hist = current_history();
225234
cur_hist; cur_hist = next_history())
226235
for (cur_ptr = cur_hist->line; *cur_ptr; cur_ptr++)
227-
if (*cur_ptr == '\0')
236+
if (*cur_ptr == NL_IN_HISTORY)
228237
*cur_ptr = '\n';
229238
}
230239

0 commit comments

Comments
 (0)