mirror of
https://https.git.savannah.gnu.org/git/gnulib.git
synced 2026-05-13 15:13:36 +00:00
quotearg: minimize shell quoting using double quotes
I.E. 'it'\''s awkward like this'; "it's better like this" * lib/quotearg.c (quotearg_buffer_restyled): If an ASCII single quote in encountered then use double quotes (c style quoting) when possible, as it simplifies the quoting. * tests/test-quotearg-simple.c: Add test cases. * tests/test-quotearg.h (use_quotearg_buffer): Adjust to account for the fact we now may write beyond the returned length.
This commit is contained in:
10
ChangeLog
10
ChangeLog
@@ -1,3 +1,13 @@
|
||||
2016-10-03 Pádraig Brady <P@draigBrady.com>
|
||||
|
||||
quotearg: minimize shell quoting using double quotes
|
||||
* lib/quotearg.c (quotearg_buffer_restyled): If an ASCII single
|
||||
quote in encountered then use double quotes (c style quoting)
|
||||
when possible, as it simplifies the quoting.
|
||||
* tests/test-quotearg-simple.c: Add test cases.
|
||||
* tests/test-quotearg.h (use_quotearg_buffer): Adjust to account
|
||||
for the fact we now may write beyond the returned length.
|
||||
|
||||
2016-10-02 Jim Meyering <meyering@fb.com>
|
||||
|
||||
vasnprintf.c: avoid spurious warning from GCC 7
|
||||
|
||||
@@ -258,6 +258,8 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize,
|
||||
bool unibyte_locale = MB_CUR_MAX == 1;
|
||||
bool elide_outer_quotes = (flags & QA_ELIDE_OUTER_QUOTES) != 0;
|
||||
bool pending_shell_escape_end = false;
|
||||
bool encountered_single_quote = false;
|
||||
bool all_c_and_shell_quote_compat = true;
|
||||
|
||||
#define STORE(c) \
|
||||
do \
|
||||
@@ -388,6 +390,7 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize,
|
||||
unsigned char esc;
|
||||
bool is_right_quote = false;
|
||||
bool escaping = false;
|
||||
bool c_and_shell_quote_compat = false;
|
||||
|
||||
if (backslash_escapes
|
||||
&& quoting_style != shell_always_quoting_style
|
||||
@@ -515,6 +518,8 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize,
|
||||
break;
|
||||
/* Fall through. */
|
||||
case ' ':
|
||||
c_and_shell_quote_compat = true;
|
||||
/* Fall through. */
|
||||
case '!': /* special in bash */
|
||||
case '"': case '$': case '&':
|
||||
case '(': case ')': case '*': case ';':
|
||||
@@ -533,6 +538,8 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize,
|
||||
break;
|
||||
|
||||
case '\'':
|
||||
encountered_single_quote = true;
|
||||
c_and_shell_quote_compat = true;
|
||||
if (quoting_style == shell_always_quoting_style)
|
||||
{
|
||||
if (elide_outer_quotes)
|
||||
@@ -566,6 +573,7 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize,
|
||||
them. Also, a digit or a special letter would cause
|
||||
trouble if it appeared in quote_these_too, but that's also
|
||||
documented as not accepting them. */
|
||||
c_and_shell_quote_compat = true;
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -644,6 +652,8 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize,
|
||||
while (! mbsinit (&mbstate));
|
||||
}
|
||||
|
||||
c_and_shell_quote_compat = printable;
|
||||
|
||||
if (1 < m || (backslash_escapes && ! printable))
|
||||
{
|
||||
/* Output a multibyte sequence, or an escaped
|
||||
@@ -689,12 +699,26 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize,
|
||||
store_c:
|
||||
END_ESC ();
|
||||
STORE (c);
|
||||
|
||||
if (! c_and_shell_quote_compat)
|
||||
all_c_and_shell_quote_compat = false;
|
||||
}
|
||||
|
||||
if (len == 0 && quoting_style == shell_always_quoting_style
|
||||
&& elide_outer_quotes)
|
||||
goto force_outer_quoting_style;
|
||||
|
||||
/* Single shell quotes (') are commonly enough used as an apostrophe,
|
||||
that we attempt to minimize the quoting in this case. Note itʼs
|
||||
better to use the apostrophe modifier "\u02BC" if possible, as that
|
||||
renders better and works with the word match regex \W+ etc. */
|
||||
if (quoting_style == shell_always_quoting_style && ! elide_outer_quotes
|
||||
&& all_c_and_shell_quote_compat && encountered_single_quote)
|
||||
return quotearg_buffer_restyled (buffer, buffersize, arg, argsize,
|
||||
c_quoting_style,
|
||||
flags, quote_these_too,
|
||||
left_quote, right_quote);
|
||||
|
||||
if (quote_string && !elide_outer_quotes)
|
||||
for (; *quote_string; quote_string++)
|
||||
STORE (*quote_string);
|
||||
|
||||
@@ -35,124 +35,125 @@
|
||||
static struct result_groups results_g[] = {
|
||||
/* literal_quoting_style */
|
||||
{ { "", "\0""1\0", 3, "simple", " \t\n'\"\033?""?/\\", "a:b", "a\\b",
|
||||
LQ RQ, LQ RQ },
|
||||
"a' b", LQ RQ, LQ RQ },
|
||||
{ "", "1", 1, "simple", " \t\n'\"\033?""?/\\", "a:b", "a\\b",
|
||||
LQ RQ, LQ RQ },
|
||||
"a' b", LQ RQ, LQ RQ },
|
||||
{ "", "1", 1, "simple", " \t\n'\"\033?""?/\\", "a:b", "a\\b",
|
||||
LQ RQ, LQ RQ } },
|
||||
"a' b", LQ RQ, LQ RQ } },
|
||||
|
||||
/* shell_quoting_style */
|
||||
{ { "''", "\0""1\0", 3, "simple", "' \t\n'\\''\"\033?""?/\\'", "a:b",
|
||||
"'a\\b'", LQ RQ, LQ RQ },
|
||||
"'a\\b'", "\"a' b\"", LQ RQ, LQ RQ },
|
||||
{ "''", "1", 1, "simple", "' \t\n'\\''\"\033?""?/\\'", "a:b",
|
||||
"'a\\b'", LQ RQ, LQ RQ },
|
||||
"'a\\b'", "\"a' b\"", LQ RQ, LQ RQ },
|
||||
{ "''", "1", 1, "simple", "' \t\n'\\''\"\033?""?/\\'", "'a:b'",
|
||||
"'a\\b'", LQ RQ, LQ RQ } },
|
||||
"'a\\b'", "\"a' b\"", LQ RQ, LQ RQ } },
|
||||
|
||||
/* shell_always_quoting_style */
|
||||
{ { "''", "'\0""1\0'", 5, "'simple'", "' \t\n'\\''\"\033?""?/\\'", "'a:b'",
|
||||
"'a\\b'", "'" LQ RQ "'", "'" LQ RQ "'" },
|
||||
"'a\\b'", "\"a' b\"", "'" LQ RQ "'", "'" LQ RQ "'" },
|
||||
{ "''", "'1'", 3, "'simple'", "' \t\n'\\''\"\033?""?/\\'", "'a:b'",
|
||||
"'a\\b'", "'" LQ RQ "'", "'" LQ RQ "'" },
|
||||
"'a\\b'", "\"a' b\"", "'" LQ RQ "'", "'" LQ RQ "'" },
|
||||
{ "''", "'1'", 3, "'simple'", "' \t\n'\\''\"\033?""?/\\'", "'a:b'",
|
||||
"'a\\b'", "'" LQ RQ "'", "'" LQ RQ "'" } },
|
||||
"'a\\b'", "\"a' b\"", "'" LQ RQ "'", "'" LQ RQ "'" } },
|
||||
|
||||
/* shell_escape_quoting_style */
|
||||
{ { "''", "''$'\\0''1'$'\\0'", 15, "simple",
|
||||
"' '$'\\t\\n'\\''\"'$'\\033''?""?/\\'", "a:b",
|
||||
"'a\\b'", "''$'" LQ_ENC RQ_ENC "'", LQ RQ },
|
||||
"'a\\b'", "\"a' b\"", "''$'" LQ_ENC RQ_ENC "'", LQ RQ },
|
||||
{ "''", "''$'\\0''1'$'\\0'", 15, "simple",
|
||||
"' '$'\\t\\n'\\''\"'$'\\033''?""?/\\'", "a:b",
|
||||
"'a\\b'", "''$'" LQ_ENC RQ_ENC "'", LQ RQ },
|
||||
"'a\\b'", "\"a' b\"", "''$'" LQ_ENC RQ_ENC "'", LQ RQ },
|
||||
{ "''", "''$'\\0''1'$'\\0'", 15, "simple",
|
||||
"' '$'\\t\\n'\\''\"'$'\\033''?""?/\\'", "'a:b'",
|
||||
"'a\\b'", "''$'" LQ_ENC RQ_ENC "'", LQ RQ } },
|
||||
"'a\\b'", "\"a' b\"", "''$'" LQ_ENC RQ_ENC "'", LQ RQ } },
|
||||
|
||||
/* shell_escape_always_quoting_style */
|
||||
{ { "''", "''$'\\0''1'$'\\0'", 15, "'simple'",
|
||||
"' '$'\\t\\n'\\''\"'$'\\033''?""?/\\'", "'a:b'",
|
||||
"'a\\b'", "''$'" LQ_ENC RQ_ENC "'", "'" LQ RQ "'" },
|
||||
"'a\\b'", "\"a' b\"", "''$'" LQ_ENC RQ_ENC "'", "'" LQ RQ "'" },
|
||||
{ "''", "''$'\\0''1'$'\\0'", 15, "'simple'",
|
||||
"' '$'\\t\\n'\\''\"'$'\\033''?""?/\\'", "'a:b'",
|
||||
"'a\\b'", "''$'" LQ_ENC RQ_ENC "'", "'" LQ RQ "'" },
|
||||
"'a\\b'", "\"a' b\"", "''$'" LQ_ENC RQ_ENC "'", "'" LQ RQ "'" },
|
||||
{ "''", "''$'\\0''1'$'\\0'", 15, "'simple'",
|
||||
"' '$'\\t\\n'\\''\"'$'\\033''?""?/\\'", "'a:b'",
|
||||
"'a\\b'", "''$'" LQ_ENC RQ_ENC "'", "'" LQ RQ "'" } },
|
||||
"'a\\b'", "\"a' b\"", "''$'" LQ_ENC RQ_ENC "'", "'" LQ RQ "'" } },
|
||||
|
||||
/* c_quoting_style */
|
||||
{ { "\"\"", "\"\\0001\\0\"", 9, "\"simple\"",
|
||||
"\" \\t\\n'\\\"\\033?""?/\\\\\"", "\"a:b\"", "\"a\\\\b\"",
|
||||
"\"" LQ_ENC RQ_ENC "\"", "\"" LQ RQ "\"" },
|
||||
"\"a' b\"", "\"" LQ_ENC RQ_ENC "\"", "\"" LQ RQ "\"" },
|
||||
{ "\"\"", "\"\\0001\\0\"", 9, "\"simple\"",
|
||||
"\" \\t\\n'\\\"\\033?""?/\\\\\"", "\"a:b\"", "\"a\\\\b\"",
|
||||
"\"" LQ_ENC RQ_ENC "\"", "\"" LQ RQ "\"" },
|
||||
"\"a' b\"", "\"" LQ_ENC RQ_ENC "\"", "\"" LQ RQ "\"" },
|
||||
{ "\"\"", "\"\\0001\\0\"", 9, "\"simple\"",
|
||||
"\" \\t\\n'\\\"\\033?""?/\\\\\"", "\"a\\:b\"", "\"a\\\\b\"",
|
||||
"\"" LQ_ENC RQ_ENC "\"", "\"" LQ RQ "\"" } },
|
||||
"\"a' b\"", "\"" LQ_ENC RQ_ENC "\"", "\"" LQ RQ "\"" } },
|
||||
|
||||
/* c_maybe_quoting_style */
|
||||
{ { "", "\"\\0001\\0\"", 9, "simple", "\" \\t\\n'\\\"\\033?""?/\\\\\"",
|
||||
"a:b", "a\\b", "\"" LQ_ENC RQ_ENC "\"", LQ RQ },
|
||||
"a:b", "a\\b", "a' b", "\"" LQ_ENC RQ_ENC "\"", LQ RQ },
|
||||
{ "", "\"\\0001\\0\"", 9, "simple", "\" \\t\\n'\\\"\\033?""?/\\\\\"",
|
||||
"a:b", "a\\b", "\"" LQ_ENC RQ_ENC "\"", LQ RQ },
|
||||
"a:b", "a\\b", "a' b", "\"" LQ_ENC RQ_ENC "\"", LQ RQ },
|
||||
{ "", "\"\\0001\\0\"", 9, "simple", "\" \\t\\n'\\\"\\033?""?/\\\\\"",
|
||||
"\"a:b\"", "a\\b", "\"" LQ_ENC RQ_ENC "\"", LQ RQ } },
|
||||
"\"a:b\"", "a\\b", "a' b", "\"" LQ_ENC RQ_ENC "\"", LQ RQ } },
|
||||
|
||||
/* escape_quoting_style */
|
||||
{ { "", "\\0001\\0", 7, "simple", " \\t\\n'\"\\033?""?/\\\\", "a:b",
|
||||
"a\\\\b", LQ_ENC RQ_ENC, LQ RQ },
|
||||
"a\\\\b", "a' b", LQ_ENC RQ_ENC, LQ RQ },
|
||||
{ "", "\\0001\\0", 7, "simple", " \\t\\n'\"\\033?""?/\\\\", "a:b",
|
||||
"a\\\\b", LQ_ENC RQ_ENC, LQ RQ },
|
||||
"a\\\\b", "a' b", LQ_ENC RQ_ENC, LQ RQ },
|
||||
{ "", "\\0001\\0", 7, "simple", " \\t\\n'\"\\033?""?/\\\\", "a\\:b",
|
||||
"a\\\\b", LQ_ENC RQ_ENC, LQ RQ } },
|
||||
"a\\\\b", "a' b", LQ_ENC RQ_ENC, LQ RQ } },
|
||||
|
||||
/* locale_quoting_style */
|
||||
{ { "''", "'\\0001\\0'", 9, "'simple'", "' \\t\\n\\'\"\\033?""?/\\\\'",
|
||||
"'a:b'", "'a\\\\b'", "'" LQ_ENC RQ_ENC "'", "'" LQ RQ "'" },
|
||||
"'a:b'", "'a\\\\b'", "'a\\' b'", "'" LQ_ENC RQ_ENC "'", "'" LQ RQ "'" },
|
||||
{ "''", "'\\0001\\0'", 9, "'simple'", "' \\t\\n\\'\"\\033?""?/\\\\'",
|
||||
"'a:b'", "'a\\\\b'", "'" LQ_ENC RQ_ENC "'", "'" LQ RQ "'" },
|
||||
"'a:b'", "'a\\\\b'", "'a\\' b'", "'" LQ_ENC RQ_ENC "'", "'" LQ RQ "'" },
|
||||
{ "''", "'\\0001\\0'", 9, "'simple'", "' \\t\\n\\'\"\\033?""?/\\\\'",
|
||||
"'a\\:b'", "'a\\\\b'", "'" LQ_ENC RQ_ENC "'", "'" LQ RQ "'" } },
|
||||
"'a\\:b'", "'a\\\\b'", "'a\\' b'",
|
||||
"'" LQ_ENC RQ_ENC "'", "'" LQ RQ "'" } },
|
||||
|
||||
/* clocale_quoting_style */
|
||||
{ { "\"\"", "\"\\0001\\0\"", 9, "\"simple\"",
|
||||
"\" \\t\\n'\\\"\\033?""?/\\\\\"", "\"a:b\"", "\"a\\\\b\"",
|
||||
"\"" LQ_ENC RQ_ENC "\"", "\"" LQ RQ "\"" },
|
||||
"\"a' b\"", "\"" LQ_ENC RQ_ENC "\"", "\"" LQ RQ "\"" },
|
||||
{ "\"\"", "\"\\0001\\0\"", 9, "\"simple\"",
|
||||
"\" \\t\\n'\\\"\\033?""?/\\\\\"", "\"a:b\"", "\"a\\\\b\"",
|
||||
"\"" LQ_ENC RQ_ENC "\"", "\"" LQ RQ "\"" },
|
||||
"\"a' b\"", "\"" LQ_ENC RQ_ENC "\"", "\"" LQ RQ "\"" },
|
||||
{ "\"\"", "\"\\0001\\0\"", 9, "\"simple\"",
|
||||
"\" \\t\\n'\\\"\\033?""?/\\\\\"", "\"a\\:b\"", "\"a\\\\b\"",
|
||||
"\"" LQ_ENC RQ_ENC "\"", "\"" LQ RQ "\"" } }
|
||||
"\"a' b\"", "\"" LQ_ENC RQ_ENC "\"", "\"" LQ RQ "\"" } }
|
||||
};
|
||||
|
||||
static struct result_groups flag_results[] = {
|
||||
/* literal_quoting_style and QA_ELIDE_NULL_BYTES */
|
||||
{ { "", "1", 1, "simple", " \t\n'\"\033?""?/\\", "a:b", "a\\b", LQ RQ,
|
||||
LQ RQ },
|
||||
{ "", "1", 1, "simple", " \t\n'\"\033?""?/\\", "a:b", "a\\b", LQ RQ,
|
||||
LQ RQ },
|
||||
{ "", "1", 1, "simple", " \t\n'\"\033?""?/\\", "a:b", "a\\b", LQ RQ,
|
||||
LQ RQ } },
|
||||
{ { "", "1", 1, "simple", " \t\n'\"\033?""?/\\", "a:b", "a\\b", "a' b",
|
||||
LQ RQ, LQ RQ },
|
||||
{ "", "1", 1, "simple", " \t\n'\"\033?""?/\\", "a:b", "a\\b", "a' b",
|
||||
LQ RQ, LQ RQ },
|
||||
{ "", "1", 1, "simple", " \t\n'\"\033?""?/\\", "a:b", "a\\b", "a' b",
|
||||
LQ RQ, LQ RQ } },
|
||||
|
||||
/* c_quoting_style and QA_ELIDE_OUTER_QUOTES */
|
||||
{ { "", "\"\\0001\\0\"", 9, "simple", "\" \\t\\n'\\\"\\033?""?/\\\\\"",
|
||||
"a:b", "a\\b", "\"" LQ_ENC RQ_ENC "\"", LQ RQ },
|
||||
"a:b", "a\\b", "a' b", "\"" LQ_ENC RQ_ENC "\"", LQ RQ },
|
||||
{ "", "\"\\0001\\0\"", 9, "simple", "\" \\t\\n'\\\"\\033?""?/\\\\\"",
|
||||
"a:b", "a\\b", "\"" LQ_ENC RQ_ENC "\"", LQ RQ },
|
||||
"a:b", "a\\b", "a' b", "\"" LQ_ENC RQ_ENC "\"", LQ RQ },
|
||||
{ "", "\"\\0001\\0\"", 9, "simple", "\" \\t\\n'\\\"\\033?""?/\\\\\"",
|
||||
"\"a:b\"", "a\\b", "\"" LQ_ENC RQ_ENC "\"", LQ RQ } },
|
||||
"\"a:b\"", "a\\b", "a' b", "\"" LQ_ENC RQ_ENC "\"", LQ RQ } },
|
||||
|
||||
/* c_quoting_style and QA_SPLIT_TRIGRAPHS */
|
||||
{ { "\"\"", "\"\\0001\\0\"", 9, "\"simple\"",
|
||||
"\" \\t\\n'\\\"\\033?\"\"?/\\\\\"", "\"a:b\"", "\"a\\\\b\"",
|
||||
"\"" LQ_ENC RQ_ENC "\"", "\"" LQ RQ "\"" },
|
||||
"\"a' b\"", "\"" LQ_ENC RQ_ENC "\"", "\"" LQ RQ "\"" },
|
||||
{ "\"\"", "\"\\0001\\0\"", 9, "\"simple\"",
|
||||
"\" \\t\\n'\\\"\\033?\"\"?/\\\\\"", "\"a:b\"", "\"a\\\\b\"",
|
||||
"\"" LQ_ENC RQ_ENC "\"", "\"" LQ RQ "\"" },
|
||||
"\"a' b\"", "\"" LQ_ENC RQ_ENC "\"", "\"" LQ RQ "\"" },
|
||||
{ "\"\"", "\"\\0001\\0\"", 9, "\"simple\"",
|
||||
"\" \\t\\n'\\\"\\033?\"\"?/\\\\\"", "\"a\\:b\"", "\"a\\\\b\"",
|
||||
"\"" LQ_ENC RQ_ENC "\"", "\"" LQ RQ "\"" } }
|
||||
"\"a' b\"", "\"" LQ_ENC RQ_ENC "\"", "\"" LQ RQ "\"" } }
|
||||
};
|
||||
|
||||
static char const *custom_quotes[][2] = {
|
||||
@@ -169,79 +170,79 @@ static struct result_groups custom_results[] = {
|
||||
/* left_quote = right_quote = "" */
|
||||
{ { "", "\\0001\\0", 7, "simple",
|
||||
" \\t\\n'\"\\033?""?/\\\\", "a:b", "a\\\\b",
|
||||
LQ_ENC RQ_ENC, LQ RQ },
|
||||
"a' b", LQ_ENC RQ_ENC, LQ RQ },
|
||||
{ "", "\\0001\\0", 7, "simple",
|
||||
" \\t\\n'\"\\033?""?/\\\\", "a:b", "a\\\\b",
|
||||
LQ_ENC RQ_ENC, LQ RQ },
|
||||
"a' b", LQ_ENC RQ_ENC, LQ RQ },
|
||||
{ "", "\\0001\\0", 7, "simple",
|
||||
" \\t\\n'\"\\033?""?/\\\\", "a\\:b", "a\\\\b",
|
||||
LQ_ENC RQ_ENC, LQ RQ } },
|
||||
"a' b", LQ_ENC RQ_ENC, LQ RQ } },
|
||||
|
||||
/* left_quote = right_quote = "'" */
|
||||
{ { "''", "'\\0001\\0'", 9, "'simple'",
|
||||
"' \\t\\n\\'\"\\033?""?/\\\\'", "'a:b'", "'a\\\\b'",
|
||||
"'" LQ_ENC RQ_ENC "'", "'" LQ RQ "'" },
|
||||
"'a\\' b'", "'" LQ_ENC RQ_ENC "'", "'" LQ RQ "'" },
|
||||
{ "''", "'\\0001\\0'", 9, "'simple'",
|
||||
"' \\t\\n\\'\"\\033?""?/\\\\'", "'a:b'", "'a\\\\b'",
|
||||
"'" LQ_ENC RQ_ENC "'", "'" LQ RQ "'" },
|
||||
"'a\\' b'", "'" LQ_ENC RQ_ENC "'", "'" LQ RQ "'" },
|
||||
{ "''", "'\\0001\\0'", 9, "'simple'",
|
||||
"' \\t\\n\\'\"\\033?""?/\\\\'", "'a\\:b'", "'a\\\\b'",
|
||||
"'" LQ_ENC RQ_ENC "'", "'" LQ RQ "'" } },
|
||||
"'a\\' b'", "'" LQ_ENC RQ_ENC "'", "'" LQ RQ "'" } },
|
||||
|
||||
/* left_quote = "(" and right_quote = ")" */
|
||||
{ { "()", "(\\0001\\0)", 9, "(simple)",
|
||||
"( \\t\\n'\"\\033?""?/\\\\)", "(a:b)", "(a\\\\b)",
|
||||
"(" LQ_ENC RQ_ENC ")", "(" LQ RQ ")" },
|
||||
"(a' b)", "(" LQ_ENC RQ_ENC ")", "(" LQ RQ ")" },
|
||||
{ "()", "(\\0001\\0)", 9, "(simple)",
|
||||
"( \\t\\n'\"\\033?""?/\\\\)", "(a:b)", "(a\\\\b)",
|
||||
"(" LQ_ENC RQ_ENC ")", "(" LQ RQ ")" },
|
||||
"(a' b)", "(" LQ_ENC RQ_ENC ")", "(" LQ RQ ")" },
|
||||
{ "()", "(\\0001\\0)", 9, "(simple)",
|
||||
"( \\t\\n'\"\\033?""?/\\\\)", "(a\\:b)", "(a\\\\b)",
|
||||
"(" LQ_ENC RQ_ENC ")", "(" LQ RQ ")" } },
|
||||
"(a' b)", "(" LQ_ENC RQ_ENC ")", "(" LQ RQ ")" } },
|
||||
|
||||
/* left_quote = ":" and right_quote = " " */
|
||||
{ { ": ", ":\\0001\\0 ", 9, ":simple ",
|
||||
":\\ \\t\\n'\"\\033?""?/\\\\ ", ":a:b ", ":a\\\\b ",
|
||||
":" LQ_ENC RQ_ENC " ", ":" LQ RQ " " },
|
||||
":a'\\ b ", ":" LQ_ENC RQ_ENC " ", ":" LQ RQ " " },
|
||||
{ ": ", ":\\0001\\0 ", 9, ":simple ",
|
||||
":\\ \\t\\n'\"\\033?""?/\\\\ ", ":a:b ", ":a\\\\b ",
|
||||
":" LQ_ENC RQ_ENC " ", ":" LQ RQ " " },
|
||||
":a'\\ b ", ":" LQ_ENC RQ_ENC " ", ":" LQ RQ " " },
|
||||
{ ": ", ":\\0001\\0 ", 9, ":simple ",
|
||||
":\\ \\t\\n'\"\\033?""?/\\\\ ", ":a\\:b ", ":a\\\\b ",
|
||||
":" LQ_ENC RQ_ENC " ", ":" LQ RQ " " } },
|
||||
":a'\\ b ", ":" LQ_ENC RQ_ENC " ", ":" LQ RQ " " } },
|
||||
|
||||
/* left_quote = " " and right_quote = ":" */
|
||||
{ { " :", " \\0001\\0:", 9, " simple:",
|
||||
" \\t\\n'\"\\033?""?/\\\\:", " a\\:b:", " a\\\\b:",
|
||||
" " LQ_ENC RQ_ENC ":", " " LQ RQ ":" },
|
||||
" a' b:", " " LQ_ENC RQ_ENC ":", " " LQ RQ ":" },
|
||||
{ " :", " \\0001\\0:", 9, " simple:",
|
||||
" \\t\\n'\"\\033?""?/\\\\:", " a\\:b:", " a\\\\b:",
|
||||
" " LQ_ENC RQ_ENC ":", " " LQ RQ ":" },
|
||||
" a' b:", " " LQ_ENC RQ_ENC ":", " " LQ RQ ":" },
|
||||
{ " :", " \\0001\\0:", 9, " simple:",
|
||||
" \\t\\n'\"\\033?""?/\\\\:", " a\\:b:", " a\\\\b:",
|
||||
" " LQ_ENC RQ_ENC ":", " " LQ RQ ":" } },
|
||||
" a' b:", " " LQ_ENC RQ_ENC ":", " " LQ RQ ":" } },
|
||||
|
||||
/* left_quote = "# " and right_quote = "\n" */
|
||||
{ { "# \n", "# \\0001\\0\n", 10, "# simple\n",
|
||||
"# \\t\\n'\"\\033?""?/\\\\\n", "# a:b\n", "# a\\\\b\n",
|
||||
"# " LQ_ENC RQ_ENC "\n", "# " LQ RQ "\n" },
|
||||
"# a' b\n", "# " LQ_ENC RQ_ENC "\n", "# " LQ RQ "\n" },
|
||||
{ "# \n", "# \\0001\\0\n", 10, "# simple\n",
|
||||
"# \\t\\n'\"\\033?""?/\\\\\n", "# a:b\n", "# a\\\\b\n",
|
||||
"# " LQ_ENC RQ_ENC "\n", "# " LQ RQ "\n" },
|
||||
"# a' b\n", "# " LQ_ENC RQ_ENC "\n", "# " LQ RQ "\n" },
|
||||
{ "# \n", "# \\0001\\0\n", 10, "# simple\n",
|
||||
"# \\t\\n'\"\\033?""?/\\\\\n", "# a\\:b\n", "# a\\\\b\n",
|
||||
"# " LQ_ENC RQ_ENC "\n", "# " LQ RQ "\n" } },
|
||||
"# a' b\n", "# " LQ_ENC RQ_ENC "\n", "# " LQ RQ "\n" } },
|
||||
|
||||
/* left_quote = "\"'" and right_quote = "'\"" */
|
||||
{ { "\"''\"", "\"'\\0001\\0'\"", 11, "\"'simple'\"",
|
||||
"\"' \\t\\n\\'\"\\033?""?/\\\\'\"", "\"'a:b'\"", "\"'a\\\\b'\"",
|
||||
"\"'" LQ_ENC RQ_ENC "'\"", "\"'" LQ RQ "'\"" },
|
||||
"\"'a' b'\"", "\"'" LQ_ENC RQ_ENC "'\"", "\"'" LQ RQ "'\"" },
|
||||
{ "\"''\"", "\"'\\0001\\0'\"", 11, "\"'simple'\"",
|
||||
"\"' \\t\\n\\'\"\\033?""?/\\\\'\"", "\"'a:b'\"", "\"'a\\\\b'\"",
|
||||
"\"'" LQ_ENC RQ_ENC "'\"", "\"'" LQ RQ "'\"" },
|
||||
"\"'a' b'\"", "\"'" LQ_ENC RQ_ENC "'\"", "\"'" LQ RQ "'\"" },
|
||||
{ "\"''\"", "\"'\\0001\\0'\"", 11, "\"'simple'\"",
|
||||
"\"' \\t\\n\\'\"\\033?""?/\\\\'\"", "\"'a\\:b'\"", "\"'a\\\\b'\"",
|
||||
"\"'" LQ_ENC RQ_ENC "'\"", "\"'" LQ RQ "'\"" } }
|
||||
"\"'a' b'\"", "\"'" LQ_ENC RQ_ENC "'\"", "\"'" LQ RQ "'\"" } }
|
||||
};
|
||||
|
||||
int
|
||||
|
||||
@@ -24,8 +24,9 @@ struct result_strings {
|
||||
char const *str4; /* Translation of " \t\n'\"\033?""?/\\". */
|
||||
char const *str5; /* Translation of "a:b". */
|
||||
char const *str6; /* Translation of "a\\b". */
|
||||
char const *str7a; /* Translation of LQ RQ, in ASCII charset. */
|
||||
char const *str7b; /* Translation of LQ RQ, in Latin1 or UTF-8 charset. */
|
||||
char const *str7; /* Translation of "a' b". */
|
||||
char const *str8a; /* Translation of LQ RQ, in ASCII charset. */
|
||||
char const *str8b; /* Translation of LQ RQ, in Latin1 or UTF-8 charset. */
|
||||
};
|
||||
|
||||
struct result_groups {
|
||||
@@ -43,7 +44,7 @@ struct result_groups {
|
||||
|
||||
static struct result_strings inputs = {
|
||||
"", "\0001\0", 3, "simple", " \t\n'\"\033?""?/\\", "a:b", "a\\b",
|
||||
LQ RQ, NULL
|
||||
"a' b", LQ RQ, NULL
|
||||
};
|
||||
|
||||
static void
|
||||
@@ -85,12 +86,16 @@ compare_strings (char *(func) (char const *, size_t *),
|
||||
p = func (inputs.str6, &len);
|
||||
compare (results->str6, strlen (results->str6), p, len);
|
||||
|
||||
len = strlen (inputs.str7a);
|
||||
p = func (inputs.str7a, &len);
|
||||
len = strlen (inputs.str7);
|
||||
p = func (inputs.str7, &len);
|
||||
compare (results->str7, strlen (results->str7), p, len);
|
||||
|
||||
len = strlen (inputs.str8a);
|
||||
p = func (inputs.str8a, &len);
|
||||
if (ascii_only)
|
||||
compare (results->str7a, strlen (results->str7a), p, len);
|
||||
compare (results->str8a, strlen (results->str8a), p, len);
|
||||
else
|
||||
compare (results->str7b, strlen (results->str7b), p, len);
|
||||
compare (results->str8b, strlen (results->str8b), p, len);
|
||||
}
|
||||
|
||||
static char *
|
||||
@@ -99,9 +104,10 @@ use_quotearg_buffer (const char *str, size_t *len)
|
||||
static char buf[100];
|
||||
size_t size;
|
||||
memset (buf, 0xa5, 100);
|
||||
size = quotearg_buffer (buf, 100, str, *len, NULL);
|
||||
size = quotearg_buffer (buf, 50, str, *len, NULL);
|
||||
*len = size;
|
||||
ASSERT ((unsigned char) buf[size + 1] == 0xa5);
|
||||
ASSERT ((unsigned char) buf[size] == '\0');
|
||||
ASSERT ((unsigned char) buf[50] == 0xa5);
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user