Handle "\n" -> newline expansion in the option_parser.

It makes more sense to handle escapes in configuration strings when we
parse them, rather than after-the-fact when we handle notifications that
use the relevant config options.

Do this in the proper backslash handler; rather than a naive string
replace which doesn't allow the backslash to be escaped (`\\n` => 0x5C0x0A
rather than 0x5C0x6E).
it to the proper backslash handler
This commit is contained in:
Luke Shumaker 2017-02-23 22:55:58 -05:00
parent b83363e351
commit a7b3ff1ea8
4 changed files with 10 additions and 1 deletions

View File

@ -368,7 +368,7 @@ int notification_init(notification * n, int id)
n->urls = notification_extract_markup_urls(&(n->body)); n->urls = notification_extract_markup_urls(&(n->body));
n->msg = string_replace_all("\\n", "\n", g_strdup(n->format)); n->msg = g_strdup(n->format);
n->msg = notification_replace_format("%a", n->appname, n->msg, n->msg = notification_replace_format("%a", n->appname, n->msg,
MARKUP_NO); MARKUP_NO);
n->msg = notification_replace_format("%s", n->summary, n->msg, n->msg = notification_replace_format("%s", n->summary, n->msg,

View File

@ -203,6 +203,9 @@ char *clean_value(char *value, int line_num)
case '\\': case '\\':
case '"': case '"':
break; break;
case 'n':
*unparsed = '\n';
break;
default: default:
fprintf(stderr, fprintf(stderr,
"Warning: invalid config file at line %d\n", "Warning: invalid config file at line %d\n",

View File

@ -22,9 +22,11 @@
simple = A simple string simple = A simple string
simple_with_hcomment = A simple string # a comment simple_with_hcomment = A simple string # a comment
simple_with_scomment = A simple string ; a comment simple_with_scomment = A simple string ; a comment
simple_with_nl = A simple string\nwith newline
quoted = "A quoted string" quoted = "A quoted string"
quoted_with_hcomment = "A quoted string" # a comment quoted_with_hcomment = "A quoted string" # a comment
quoted_with_scomment = "A quoted string" ; a comment quoted_with_scomment = "A quoted string" ; a comment
quoted_with_nl = "A quoted string\nwith newline"
quoted_with_quotes = "A string \"with quotes\"" quoted_with_quotes = "A string \"with quotes\""
quoted_with_escapes = "A string \\\"with escapes\\" quoted_with_escapes = "A string \\\"with escapes\\"
quoted_with_cchar = "A string; with #comment characters" # a comment quoted_with_cchar = "A string; with #comment characters" # a comment

View File

@ -52,6 +52,8 @@ TEST test_ini_get_string(void)
free(ptr); free(ptr);
ASSERT_STR_EQ("A simple string", (ptr = ini_get_string(string_section, "simple_with_scomment", ""))); ASSERT_STR_EQ("A simple string", (ptr = ini_get_string(string_section, "simple_with_scomment", "")));
free(ptr); free(ptr);
ASSERT_STR_EQ("A simple string\nwith newline", (ptr = ini_get_string(string_section, "simple_with_nl", "")));
free(ptr);
ASSERT_STR_EQ("A quoted string", (ptr = ini_get_string(string_section, "quoted", ""))); ASSERT_STR_EQ("A quoted string", (ptr = ini_get_string(string_section, "quoted", "")));
free(ptr); free(ptr);
@ -59,6 +61,8 @@ TEST test_ini_get_string(void)
free(ptr); free(ptr);
ASSERT_STR_EQ("A quoted string", (ptr = ini_get_string(string_section, "quoted_with_scomment", ""))); ASSERT_STR_EQ("A quoted string", (ptr = ini_get_string(string_section, "quoted_with_scomment", "")));
free(ptr); free(ptr);
ASSERT_STR_EQ("A quoted string\nwith newline", (ptr = ini_get_string(string_section, "quoted_with_nl", "")));
free(ptr);
ASSERT_STR_EQ("A string \"with quotes\"", (ptr = ini_get_string(string_section, "quoted_with_quotes", ""))); ASSERT_STR_EQ("A string \"with quotes\"", (ptr = ini_get_string(string_section, "quoted_with_quotes", "")));
free(ptr); free(ptr);
ASSERT_STR_EQ("A string \\\"with escapes\\", (ptr = ini_get_string(string_section, "quoted_with_escapes", ""))); ASSERT_STR_EQ("A string \\\"with escapes\\", (ptr = ini_get_string(string_section, "quoted_with_escapes", "")));