NetBSD Problem Report #57376
From www@netbsd.org Mon Apr 24 11:34:32 2023
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
by mollari.NetBSD.org (Postfix) with ESMTPS id DE7571A9239
for <gnats-bugs@gnats.NetBSD.org>; Mon, 24 Apr 2023 11:34:32 +0000 (UTC)
Message-Id: <20230424113306.2074E1A923A@mollari.NetBSD.org>
Date: Mon, 24 Apr 2023 11:33:06 +0000 (UTC)
From: jorge.giner@hotmail.com
Reply-To: jorge.giner@hotmail.com
To: gnats-bugs@NetBSD.org
Subject: libedit tab completion escapes spaces
X-Send-Pr-Version: www-1.0
>Number: 57376
>Category: lib
>Synopsis: libedit tab completion escapes spaces
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: lib-bug-people
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Mon Apr 24 11:35:00 +0000 2023
>Last-Modified: Mon Apr 24 20:05:01 +0000 2023
>Originator: Jorge
>Release: 9.3
>Organization:
none
>Environment:
Not needed.
>Description:
I use the readline interface of libedit for a little program. It's a BASIC interpreter, I implemented readline and libedit support (through its readline interface) to allow line editing. My notes show that this was on 2018-02-14 . I tested the program working in NetBSD, FreeBSD, OpenBSD and Slackware Linux. Autocompletion was working fine. Then, I can't say when, a change was made in libedit and autocompletion did not work as intended anymore.
The problem is:
I install a rl_completion_entry_function. When libedit calls that function when the user presses TAB to autocoplete the editing line, I return a string for the completion, but somehow libedit is not respecting the string I pass, but escapes spaces and quotes (I think it is supposing that it is a filename, but it shoulnd't).
Note that this is happening in other systems now: FreeBSD, and Linuxes with https://www.thrysoee.dk/editline/ . Also note that I am using only the readline interface that libedit provides. If I link against GNU readline, the behaviour is correct.
The code of my program is at:
https://github.com/jorgicor/bas55
The file using readline completion:
https://github.com/jorgicor/bas55/blob/master/src/getlin.c
I think that this behavior is happening for some years now. I'm a bit surprised that no one has reported it. Maybe the readline interface is not used that much, I don't know.
>How-To-Repeat:
I can't think of another way to test it, than to use my program. It's a little C program.
wget https://jorgicor.niobe.org/bas55/bas55-1.19.tar.gz
tar -xvzf bas55-1.19.tar.gz
cd bas55-1.19
./configure --with-libedit
make
src/bas55
The program starts and lets you write a BASIC program. Write 2 lines:
10 print "hello"
20 end
Write "list", you should see:
10 PRINT "HELLO"
20 END
Now, autocompletion for a line works this way: if you enter the number of a line and press TAB, you will get the line back. Test it with the line 10. Write 10 and press TAB. This happens:
10TAB
10\ PRINT \"HELLO\"
That is, my rl_completion entry_function is returning the string '10 PRINT "HELLO"' but libedit is escaping it. The correct will be to print_
10 PRINT "HELLO"
Note that some years have passed, but as far as I remeber this was working ok in 2018 (but maybe I am wrong, my notes say that I tested on NetBSD 7.1.1).
Also, more important, if I linnk against GNU readline instead of libedit (can't be done with this version as it is, some files need to be modified, but I can prepare something if needed) this works as intended, that is nothing is escaped.
I can provide a version that links with GNU readline if needed.
>Fix:
>Audit-Trail:
From: RVP <rvp@SDF.ORG>
To: gnats-bugs@netbsd.org
Cc:
Subject: Re: lib/57376: libedit tab completion escapes spaces
Date: Mon, 24 Apr 2023 13:59:27 +0000 (UTC)
On Mon, 24 Apr 2023, jorge.giner@hotmail.com wrote:
> The problem is:
>
> I install a rl_completion_entry_function. When libedit calls that function when the user presses TAB to autocoplete the editing line, I return a string for the completion, but somehow libedit is not respecting the string I pass, but escapes spaces and quotes (I think it is supposing that it is a filename, but it shoulnd't).
>
I'm not a readline expert, but, setting a custom
`rl_attempted_completion_function` like this works:
```
diff -urN bas55-1.19.orig/src/getlin.c bas55-1.19/src/getlin.c
--- bas55-1.19.orig/src/getlin.c 2018-02-22 21:44:11.000000000 +0000
+++ bas55-1.19/src/getlin.c 2023-04-24 13:51:44.596005000 +0000
@@ -25,6 +25,7 @@
extern char *rl_line_buffer;
extern int rl_point;
extern int rl_end;
+extern char **(*rl_attempted_completion_function)(const char *, int, int);
extern char *(*rl_completion_entry_function)(const char *, int);
extern char *rl_filename_completion_function(const char *, int);
extern void add_history(const char *);
@@ -334,9 +335,18 @@
s_question_mode = set;
}
+static char** complete_basic_line_wrapper(char* text, int start, int end)
+{
+ char** pp = malloc(2 * sizeof (char* ));
+ pp[0] = complete_basic_line(text);
+ pp[1] = NULL;
+ return pp;
+}
+
void get_line_init(void)
{
// using_history();
+ rl_attempted_completion_function = complete_basic_line_wrapper;
get_line_set_question_mode(0);
}
```
HTH,
-RVP
From: Christos Zoulas <christos@zoulas.com>
To: gnats-bugs@netbsd.org
Cc: lib-bug-people@netbsd.org,
gnats-admin@netbsd.org,
netbsd-bugs@netbsd.org,
jorge.giner@hotmail.com
Subject: Re: lib/57376: libedit tab completion escapes spaces
Date: Mon, 24 Apr 2023 10:46:20 -0400
--Apple-Mail=_AEBBEA75-5737-4006-8B1C-7B47749DDCFF
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
charset=us-ascii
Does readline escape by default? If not we should do the same...
christos
--Apple-Mail=_AEBBEA75-5737-4006-8B1C-7B47749DDCFF
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename=signature.asc
Content-Type: application/pgp-signature;
name=signature.asc
Content-Description: Message signed with OpenPGP
-----BEGIN PGP SIGNATURE-----
Comment: GPGTools - http://gpgtools.org
iF0EARECAB0WIQS+BJlbqPkO0MDBdsRxESqxbLM7OgUCZEaWPAAKCRBxESqxbLM7
OmecAKDQof0Y31OpR0zPRhdmgnaTQ+dNLACfWhcexhODD4982vhA+fANcnIKEpk=
=Ukga
-----END PGP SIGNATURE-----
--Apple-Mail=_AEBBEA75-5737-4006-8B1C-7B47749DDCFF--
From: Jorge Giner Cordero <jorge.giner@hotmail.com>
To: "gnats-bugs@netbsd.org" <gnats-bugs@netbsd.org>
Cc: "lib-bug-people@netbsd.org" <lib-bug-people@netbsd.org>,
"gnats-admin@netbsd.org" <gnats-admin@netbsd.org>, "netbsd-bugs@netbsd.org"
<netbsd-bugs@netbsd.org>, Christos Zoulas <christos@zoulas.com>
Subject: RE: lib/57376: libedit tab completion escapes spaces
Date: Mon, 24 Apr 2023 18:56:39 +0000
--_000_GV1P194MB1906D18445B822D2DAB53B84E3679GV1P194MB1906EURP_
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
I've uploaded a new version of bas55 in case you want to check with readlin=
e. Note that nothing changes in the source, I only enable --with-readline i=
n the configure.ac that generates the configure script, to link with readli=
ne instead of libedit, that's all.
wget https://jorgicor.niobe.org/bas55/bas55-1.20.tar.gz
tar -xvzf bas55-1.20.tar.gz
cd bas55-1.20
./configure --with-libedit
make
src/bas55
10 print "hello"
LIST
10 PRINT "HELLO"
10<TAB>
10\ PRINT \"HELLO\"
quit
Now with GNU readline, I assume it is installed through pkgin. I'm sorry, I=
don't use NetBSD very often and adding these LDFLAGS is my only idea to ma=
ke this copmile and run, I don't know if there is another better way to do =
it. Anyway, it works:
./configure LDFLAGS=3D"-L/usr/pkg/lib -Wl,-R/usr/pkg/lib" --with-readline
make
src/bas55
10 print "hello"
10<TAB>
10 PRINT "HELLO"
--_000_GV1P194MB1906D18445B822D2DAB53B84E3679GV1P194MB1906EURP_
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<html>
<head>
<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Diso-8859-=
1">
<style type=3D"text/css" style=3D"display:none;"> P {margin-top:0;margin-bo=
ttom:0;} </style>
</head>
<body dir=3D"ltr">
<div class=3D"elementToProof" style=3D"font-family: Calibri, Helvetica, san=
s-serif; font-size: 12pt; color: rgb(0, 0, 0);">
I've uploaded a new version of bas55 in case you want to check with readlin=
e. Note that nothing changes in the source, I only enable --with-readline i=
n the configure.ac that generates the configure script, to link with readli=
ne instead of libedit, that's all.<br>
</div>
<div class=3D"elementToProof" style=3D"font-family: Calibri, Helvetica, san=
s-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div class=3D"elementToProof" style=3D"font-family: Calibri, Helvetica, san=
s-serif; font-size: 12pt; color: rgb(0, 0, 0);">
wget <a href=3D"https://jorgicor.niobe.org/bas55/bas55-1.20.tar.gz" id=3D"L=
Plnk549258">
https://jorgicor.niobe.org/bas55/bas55-1.20.tar.gz</a></div>
<div class=3D"elementToProof" style=3D"font-family: Calibri, Helvetica, san=
s-serif; font-size: 12pt; color: rgb(0, 0, 0);">
tar -xvzf bas55-1.20.tar.gz</div>
<div class=3D"elementToProof" style=3D"font-family: Calibri, Helvetica, san=
s-serif; font-size: 12pt; color: rgb(0, 0, 0);">
cd bas55-1.20</div>
<div class=3D"elementToProof" style=3D"font-family: Calibri, Helvetica, san=
s-serif; font-size: 12pt; color: rgb(0, 0, 0);">
./configure --with-libedit</div>
<div class=3D"elementToProof" style=3D"font-family: Calibri, Helvetica, san=
s-serif; font-size: 12pt; color: rgb(0, 0, 0);">
make</div>
<div class=3D"elementToProof" style=3D"font-family: Calibri, Helvetica, san=
s-serif; font-size: 12pt; color: rgb(0, 0, 0);">
src/bas55</div>
<div class=3D"elementToProof" style=3D"font-family: Calibri, Helvetica, san=
s-serif; font-size: 12pt; color: rgb(0, 0, 0);">
10 print "hello"</div>
<div class=3D"elementToProof" style=3D"font-family: Calibri, Helvetica, san=
s-serif; font-size: 12pt; color: rgb(0, 0, 0);">
LIST</div>
<div class=3D"elementToProof" style=3D"font-family: Calibri, Helvetica, san=
s-serif; font-size: 12pt; color: rgb(0, 0, 0);">
10 PRINT "HELLO"</div>
<div class=3D"elementToProof" style=3D"font-family: Calibri, Helvetica, san=
s-serif; font-size: 12pt; color: rgb(0, 0, 0);">
10<TAB></div>
<div class=3D"elementToProof" style=3D"font-family: Calibri, Helvetica, san=
s-serif; font-size: 12pt; color: rgb(0, 0, 0);">
10\ PRINT \"HELLO\"</div>
<div class=3D"elementToProof" style=3D"font-family: Calibri, Helvetica, san=
s-serif; font-size: 12pt; color: rgb(0, 0, 0);">
quit</div>
<div class=3D"elementToProof" style=3D"font-family: Calibri, Helvetica, san=
s-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div class=3D"elementToProof" style=3D"font-family: Calibri, Helvetica, san=
s-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Now with GNU readline, I assume it is installed through pkgin. I'm sorry, I=
don't use NetBSD very often and adding these LDFLAGS is my only idea to ma=
ke this copmile and run, I don't know if there is another better way to do =
it. Anyway, it works:</div>
<div class=3D"elementToProof" style=3D"font-family: Calibri, Helvetica, san=
s-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div class=3D"elementToProof" style=3D"font-family: Calibri, Helvetica, san=
s-serif; font-size: 12pt; color: rgb(0, 0, 0);">
./configure LDFLAGS=3D"-L/usr/pkg/lib -Wl,-R/usr/pkg/lib" --with-=
readline</div>
<div class=3D"elementToProof" style=3D"font-family: Calibri, Helvetica, san=
s-serif; font-size: 12pt; color: rgb(0, 0, 0);">
make</div>
<div class=3D"elementToProof" style=3D"font-family: Calibri, Helvetica, san=
s-serif; font-size: 12pt; color: rgb(0, 0, 0);">
src/bas55</div>
<div class=3D"elementToProof" style=3D"font-family: Calibri, Helvetica, san=
s-serif; font-size: 12pt; color: rgb(0, 0, 0);">
10 print "hello"</div>
<div class=3D"elementToProof" style=3D"font-family: Calibri, Helvetica, san=
s-serif; font-size: 12pt; color: rgb(0, 0, 0);">
10<TAB></div>
<div class=3D"elementToProof" style=3D"font-family: Calibri, Helvetica, san=
s-serif; font-size: 12pt; color: rgb(0, 0, 0);">
10 PRINT "HELLO"</div>
</body>
</html>
--_000_GV1P194MB1906D18445B822D2DAB53B84E3679GV1P194MB1906EURP_--
From: "Christos Zoulas" <christos@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/57376 CVS commit: src/lib/libedit
Date: Mon, 24 Apr 2023 16:02:53 -0400
Module Name: src
Committed By: christos
Date: Mon Apr 24 20:02:53 UTC 2023
Modified Files:
src/lib/libedit: readline.c
Log Message:
PR/57376: Jorge Giner: readline file completion does not quote; do the same.
To generate a diff of this commit:
cvs rdiff -u -r1.179 -r1.180 src/lib/libedit/readline.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
(Contact us)
$NetBSD: query-full-pr,v 1.47 2022/09/11 19:34:41 kim Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2023
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.