Module Name:    src
Committed By:   christos
Date:           Sun Sep 26 13:45:37 UTC 2021

Modified Files:
        src/lib/libedit: filecomplete.c

Log Message:
- 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


To generate a diff of this commit:
cvs rdiff -u -r1.68 -r1.69 src/lib/libedit/filecomplete.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libedit/filecomplete.c
diff -u src/lib/libedit/filecomplete.c:1.68 src/lib/libedit/filecomplete.c:1.69
--- src/lib/libedit/filecomplete.c:1.68	Wed May  5 10:49:59 2021
+++ src/lib/libedit/filecomplete.c	Sun Sep 26 09:45:37 2021
@@ -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 @@ fn_tilde_expand(const char *txt)
 	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 @@ escape_filename(EditLine * el, const cha
 	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 @@ fn_filename_completion_function(const ch
 	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 @@ fn_filename_completion_function(const ch
 				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));

Reply via email to