Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libedit - Completion should not add a quote at the end o...



details:   https://anonhg.NetBSD.org/src/rev/7a22847bf677
branches:  trunk
changeset: 1023789:7a22847bf677
user:      christos <christos%NetBSD.org@localhost>
date:      Sun Sep 26 13:45:37 2021 +0000

description:
- Completion should not add a quote at the end of the line to match an
  already quoted quote. (Piotr Stefaniak)
- fix lint unconst warnings for strchr

diffstat:

 lib/libedit/filecomplete.c |  29 ++++++++++++++++-------------
 1 files changed, 16 insertions(+), 13 deletions(-)

diffs (87 lines):

diff -r 594587f0d4ac -r 7a22847bf677 lib/libedit/filecomplete.c
--- a/lib/libedit/filecomplete.c        Sun Sep 26 13:43:30 2021 +0000
+++ b/lib/libedit/filecomplete.c        Sun Sep 26 13:45:37 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: filecomplete.c,v 1.68 2021/05/05 14:49:59 christos Exp $       */
+/*     $NetBSD: filecomplete.c,v 1.69 2021/09/26 13:45:37 christos Exp $       */
 
 /*-
  * Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include "config.h"
 #if !defined(lint) && !defined(SCCSID)
-__RCSID("$NetBSD: filecomplete.c,v 1.68 2021/05/05 14:49:59 christos Exp $");
+__RCSID("$NetBSD: filecomplete.c,v 1.69 2021/09/26 13:45:37 christos Exp $");
 #endif /* not lint && not SCCSID */
 
 #include <sys/types.h>
@@ -69,20 +69,21 @@
        char pwbuf[1024];
 #endif
        struct passwd *pass;
+       const char *pos;
        char *temp;
        size_t len = 0;
 
        if (txt[0] != '~')
                return strdup(txt);
 
-       temp = strchr(txt + 1, '/');
-       if (temp == NULL) {
+       pos = strchr(txt + 1, '/');
+       if (pos == NULL) {
                temp = strdup(txt + 1);
                if (temp == NULL)
                        return NULL;
        } else {
                /* text until string after slash */
-               len = (size_t)(temp - txt + 1);
+               len = (size_t)(pos - txt + 1);
                temp = el_calloc(len, sizeof(*temp));
                if (temp == NULL)
                        return NULL;
@@ -212,9 +213,10 @@
        while (temp != el->el_line.cursor) {
                /*
                 * If we see a single quote but have not seen a double quote
-                * so far set/unset s_quote
+                * so far set/unset s_quote, unless it is already quoted
                 */
-               if (temp[0] == '\'' && !d_quoted)
+               if (temp[0] == '\'' && !d_quoted &&
+                   (temp == el->el_line.buffer || temp[-1] != '\\'))
                        s_quoted = !s_quoted;
                /*
                 * vice versa to the above condition
@@ -327,14 +329,15 @@
        static size_t filename_len = 0;
        struct dirent *entry;
        char *temp;
+       const char *pos;
        size_t len;
 
        if (state == 0 || dir == NULL) {
-               temp = strrchr(text, '/');
-               if (temp) {
+               pos = strrchr(text, '/');
+               if (pos) {
                        char *nptr;
-                       temp++;
-                       nptr = el_realloc(filename, (strlen(temp) + 1) *
+                       pos++;
+                       nptr = el_realloc(filename, (strlen(pos) + 1) *
                            sizeof(*nptr));
                        if (nptr == NULL) {
                                el_free(filename);
@@ -342,8 +345,8 @@
                                return NULL;
                        }
                        filename = nptr;
-                       (void)strcpy(filename, temp);
-                       len = (size_t)(temp - text);    /* including last slash */
+                       (void)strcpy(filename, pos);
+                       len = (size_t)(pos - text);     /* including last slash */
 
                        nptr = el_realloc(dirname, (len + 1) *
                            sizeof(*nptr));



Home | Main Index | Thread Index | Old Index