mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager
synced 2024-09-06 17:14:02 +00:00
ifcfg-rh: fix svEscape() to properly handle double quoting
'\'', '~': must not be escaped with backslash. Also, within double quotes the backslash escape character is only removed before special caracters like '$' or '`'. Not in general. Yes, it means that older versions of svEscape produced invalid escape sequences that we now treat differently. But that is not realy avoidable, it was a bug that needs to be fixed.
This commit is contained in:
parent
337fc582b2
commit
d8c465a3cd
|
@ -174,8 +174,8 @@ _escape_ansic (const char *source)
|
|||
|
||||
#define _char_in_strset(ch, str) (!!strchr (""str"", (ch)))
|
||||
|
||||
#define ESC_ESCAPEES "\"'\\$~`" /* must be escaped */
|
||||
#define ESC_SPACES " \t|&;()<>" /* only require "" */
|
||||
#define ESC_ESCAPEES "\"\\$`" /* must be escaped */
|
||||
#define ESC_SPACES " '\t~|&;()<>" /* only require "" */
|
||||
|
||||
const char *
|
||||
svEscape (const char *s, char **to_free)
|
||||
|
@ -385,11 +385,8 @@ svUnescape (const char *value, char **to_free)
|
|||
/* we don't support line continuation */
|
||||
goto out_error;
|
||||
}
|
||||
if (!NM_IN_SET (value[i], '$', '`', '"', '\\')) {
|
||||
/* TODO: svEscape() is not yet ready to handle properly treating
|
||||
* double quotes. */
|
||||
//g_string_append_c (str, '\\');
|
||||
}
|
||||
if (!NM_IN_SET (value[i], '$', '`', '"', '\\'))
|
||||
g_string_append_c (str, '\\');
|
||||
}
|
||||
g_string_append_c (str, value[i]);
|
||||
i++;
|
||||
|
|
|
@ -8813,6 +8813,24 @@ test_svUnescape (void)
|
|||
V0 ("\t #a", ""),
|
||||
V0 ("\t #a\r", ""),
|
||||
V0 ("\r", ""),
|
||||
V1 ("\\\"", "\""),
|
||||
V1 ("\\`", "`"),
|
||||
V1 ("\\$", "$"),
|
||||
V1 ("\\\\", "\\"),
|
||||
V1 ("\\a", "a"),
|
||||
V1 ("\\b", "b"),
|
||||
V1 ("\\'", "'"),
|
||||
V1 ("\\~", "~"),
|
||||
V1 ("\\\t", "\t"),
|
||||
V1 ("\"\\\"\"", "\""),
|
||||
V1 ("\"\\`\"", "`"),
|
||||
V1 ("\"\\$\"", "$"),
|
||||
V1 ("\"\\\\\"", "\\"),
|
||||
V1 ("\"\\a\"", "\\a"),
|
||||
V1 ("\"\\b\"", "\\b"),
|
||||
V1 ("\"\\'\"", "\\'"),
|
||||
V1 ("\"\\~\"", "\\~"),
|
||||
V1 ("\"\\\t\"", "\\\t"),
|
||||
V0 ("ab\r", "ab"),
|
||||
V0 ("a'b'\r ", "ab"),
|
||||
V0 ("a'b' \r", "ab"),
|
||||
|
|
Loading…
Reference in a new issue