[glib] gshell: Fix parsing of comments in command lines.
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] gshell: Fix parsing of comments in command lines.
- Date: Thu, 30 Aug 2012 02:54:48 +0000 (UTC)
commit 6e4acf44b3a943906432a2bf55223ac107d8e0c2
Author: Dominique Leuenberger <dimstar opensuse org>
Date: Fri Aug 17 11:10:41 2012 +0200
gshell: Fix parsing of comments in command lines.
Fixes bug 562907
glib/gshell.c | 18 ++++++++++++++++++
glib/tests/shell.c | 2 ++
2 files changed, 20 insertions(+), 0 deletions(-)
---
diff --git a/glib/gshell.c b/glib/gshell.c
index 32cb334..6b166e1 100644
--- a/glib/gshell.c
+++ b/glib/gshell.c
@@ -520,6 +520,24 @@ tokenize_command_line (const gchar *command_line,
/* FALL THRU */
case '#':
+ if (p == command_line)
+ { /* '#' was the first char */
+ current_quote = *p;
+ break;
+ }
+ switch(*(p-1))
+ {
+ case ' ':
+ case '\n':
+ case '\0':
+ current_quote = *p;
+ break;
+ default:
+ ensure_token (¤t_token);
+ g_string_append_c (current_token, *p);
+ break;
+ }
+ break;
case '\\':
current_quote = *p;
break;
diff --git a/glib/tests/shell.c b/glib/tests/shell.c
index c1862b6..08fd3fe 100644
--- a/glib/tests/shell.c
+++ b/glib/tests/shell.c
@@ -59,6 +59,8 @@ static CmdlineTest cmdline_tests[] =
{ "foo \"yada yada \\$\\\"\"", 2, { "foo", "yada yada $\"", NULL }, -1 },
{ "foo \"c:\\\\\"", 2, { "foo", "c:\\", NULL }, -1 },
{ "foo # bla bla bla\n bar", 2, { "foo", "bar", NULL }, -1 },
+ { "foo a#b", 2, { "foo", "a#b", NULL }, -1 },
+ { "#foo", 0, { NULL }, -1 },
{ "foo bar \\", 0, { NULL }, G_SHELL_ERROR_BAD_QUOTING },
{ "foo 'bar baz", 0, { NULL }, G_SHELL_ERROR_BAD_QUOTING },
{ "foo '\"bar\" baz", 0, { NULL }, G_SHELL_ERROR_BAD_QUOTING },
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]