commit a7901dd1e0f4befdb8479aa5cb33b7f43c966ab4
parent 1695463347ea089e5647433e8970db27f032ed9b
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Thu, 6 Jul 2017 13:03:20 +0200
rcfile: don't require backslashing in the argument of 'comment'
Eradicate the need for backslashes, so that the start of the nanorc
manual becomes true, where it says that quotes inside strings don't
need to be escaped. In the bargain achieve that the empty string
always switches commenting off.
This fixes https://savannah.gnu.org/bugs/?51370,
and fixes https://savannah.gnu.org/bugs/?51394.
Diffstat:
1 file changed, 13 insertions(+), 18 deletions(-)
diff --git a/src/rcfile.c b/src/rcfile.c
@@ -879,32 +879,27 @@ void pick_up_name(const char *kind, char *ptr, char **storage)
return;
}
- free(*storage);
+ /* If the argument starts with a quote, find the terminating quote. */
+ if (*ptr == '"') {
+ char *look = ++ptr;
- /* Allow unsetting the command by using an empty string. */
- if (!strcmp(ptr, "\"\""))
- *storage = NULL;
- else if (*ptr == '"') {
- char *look, *take;
-
- look = take = *storage = mallocstrcpy(NULL, ++ptr);
+ look += strlen(ptr);
- /* Snip out the backslashes of escaped characters. */
while (*look != '"') {
- if (*look == '\0') {
+ if (--look < ptr) {
rcfile_error(N_("Argument of '%s' lacks closing \""), kind);
- free(*storage);
- *storage = NULL;
return;
- } else if (*look == '\\' && *(look + 1) != '\0') {
- look++;
}
- *take++ = *look++;
}
- *take = '\0';
+ *look = '\0';
}
- else
- *storage = mallocstrcpy(NULL, ptr);
+
+ if (*ptr == '\0') {
+ free(*storage);
+ *storage = NULL;
+ } else
+ *storage = mallocstrcpy(*storage, ptr);
+
}
#endif /* !DISABLE_COLOR */