From 2c3b0c50b66e3fb9b58cbfc66124fc358b83ef88 Mon Sep 17 00:00:00 2001 From: Pavel Roskin Date: Thu, 31 Oct 2002 04:01:19 +0000 Subject: [PATCH] * subshell.c (subshell_name_quote): Don't quote numbers and letters if possible and safe. --- src/ChangeLog | 3 +++ src/TODO | 3 --- src/subshell.c | 26 +++++++++++++++++++------- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index cfbf11d1b..c2a684cfe 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,8 @@ 2002-10-30 Pavel Roskin + * subshell.c (subshell_name_quote): Don't quote numbers and + letters if possible and safe. + * charset.h: Provide new inline functions convert_to_display_c() and convert_from_input_c(). * view.c: Include charset.h unconditionally, use new conversion diff --git a/src/TODO b/src/TODO index 952b51a86..b827c6b3f 100644 --- a/src/TODO +++ b/src/TODO @@ -1,9 +1,6 @@ Before 4.6.0-pre2 ================= -Use paranoid quoting in subshell_name_quote() only when absolutely -necessary - it's slow, especially in UTF-8 locales. - Don't allow stdout and stderr from extfs scripts pollute the screen. reimplement "-P" in a safer way (temp file instead of stdout) - possibly diff --git a/src/subshell.c b/src/subshell.c index 77c9fac66..5af3f3c5b 100644 --- a/src/subshell.c +++ b/src/subshell.c @@ -39,6 +39,7 @@ #include /* strstr(), strcpy(), etc. */ #include /* sigaction(), sigprocmask(), etc. */ #include /* Required by dir.h & panel.h below */ +#include /* isalnum() */ #ifdef HAVE_UNISTD_H # include /* For pipe, fork, setsid, access etc */ @@ -752,8 +753,8 @@ subshell_name_quote (const char *s) /* Prevent interpreting leading `-' as a switch for `cd' */ if (*s == '-') { - *d++ = '.'; - *d++ = '/'; + *d++ = '.'; + *d++ = '/'; } /* echo in tcsh doesn't understand the "-e" option */ @@ -769,17 +770,28 @@ subshell_name_quote (const char *s) /* * Print every character in octal format with the leading backslash. - * tcsh and zsh may require 4-digit octals, bash doesn't like them. + * tcsh and zsh may require 4-digit octals, bash < 2.05b doesn't like them. */ if (subshell_type == BASH) { for (; *s; s++) { - sprintf(d, "\\%03o", (unsigned char) *s); - d += 4; + /* Must quote numbers, so that they are not glued to octals */ + if (isalpha ((unsigned char) *s)) { + sprintf (d, "%c", (unsigned char) *s); + d += 1; + } else { + sprintf (d, "\\%03o", (unsigned char) *s); + d += 4; + } } } else { for (; *s; s++) { - sprintf(d, "\\0%03o", (unsigned char) *s); - d += 5; + if (isalnum ((unsigned char) *s)) { + sprintf (d, "%c", (unsigned char) *s); + d += 1; + } else { + sprintf (d, "\\0%03o", (unsigned char) *s); + d += 5; + } } }