1
1

shell_unescape: fix recently added breakage of decoding escapy strings

This pach fixes two issues (both appear only in escapy strings):
  * tail cut of escapy string when '\\' is met
  * head cut of escapy string when '\\' is met :]

Signed-off-by: Sergei Trofimovich <slyfox@inbox.ru>
Этот коммит содержится в:
Sergei Trofimovich 2009-02-07 16:15:41 +02:00
родитель 96fc77bc3e
Коммит 97bdf084f8

Просмотреть файл

@ -1611,7 +1611,7 @@ shell_unescape(const char* text)
result = g_strdup(text); result = g_strdup(text);
return result; return result;
} }
str = g_string_new(""); str = g_string_new_len(text, readptr - text);
/* if we're here, we're standing on the first '\' */ /* if we're here, we're standing on the first '\' */
char c; char c;
@ -1622,6 +1622,9 @@ shell_unescape(const char* text)
readptr++; readptr++;
switch ((c = *readptr)) switch ((c = *readptr))
{ {
case '\0': /* end of string! malformed escape string */
goto out;
case 'n': g_string_append_c(str,'\n'); break; case 'n': g_string_append_c(str,'\n'); break;
case 'r': g_string_append_c(str,'\r'); break; case 'r': g_string_append_c(str,'\r'); break;
case 't': g_string_append_c(str,'\t'); break; case 't': g_string_append_c(str,'\t'); break;
@ -1646,8 +1649,6 @@ shell_unescape(const char* text)
case '`': case '`':
case '"': case '"':
case ';': case ';':
case '\0': /* end of string! malformed escape string */
goto out;
default: default:
g_string_append_c(str,c); break; g_string_append_c(str,c); break;
} }
@ -1659,7 +1660,6 @@ shell_unescape(const char* text)
readptr++; readptr++;
} }
out: out:
g_string_append_c(str,'\0');
result = str->str; result = str->str;
g_string_free(str,FALSE); g_string_free(str,FALSE);