shell: Handle empty comment gracefully

Parsing scripts using g_shell_parse_argv() line by line, it's useful to
have empty comments, so one can write pragraphs etc, e.g.

    # This is a comment with multiple paragraphs.
    #
    # It's useful to split things up like this at times.
    #
    # The empty comment characters makes it clear the paragraphs form a
    # single comment.
This commit is contained in:
Jonas Ådahl
2025-04-29 00:29:20 +02:00
parent 490438c416
commit 2c0c03ad27
2 changed files with 6 additions and 0 deletions

View File

@@ -580,6 +580,11 @@ tokenize_command_line (const gchar *command_line,
_("Text ended just after a “\\” character."
" (The text was “%s”)"),
command_line);
else if (current_quote == '#')
g_set_error (error,
G_SHELL_ERROR,
G_SHELL_ERROR_EMPTY_STRING,
_("Text was empty (or contained only whitespace)"));
else
g_set_error (error,
G_SHELL_ERROR,

View File

@@ -67,6 +67,7 @@ static CmdlineTest cmdline_tests[] =
{ "", 0, { NULL }, G_SHELL_ERROR_EMPTY_STRING },
{ " ", 0, { NULL }, G_SHELL_ERROR_EMPTY_STRING },
{ "# foo bar", 0, { NULL }, G_SHELL_ERROR_EMPTY_STRING },
{ "#", 0, { NULL }, G_SHELL_ERROR_EMPTY_STRING },
{"foo '/bar/summer'\\''09 tours.pdf'", 2, {"foo", "/bar/summer'09 tours.pdf", NULL}, -1}
};