Module Name: src
Committed By: jmmv
Date: Sat Feb 23 21:04:28 UTC 2013
Modified Files:
src/external/bsd/kyua-testers/dist: atf_list.c atf_list_test.c
Log Message:
Cherry-pick upstream commit 9f81e6f6fece7f7e26643022a5efb93c3595e9bc:
Escape backslashes in test metadata
The previous code in kyua-atf-tester escaped single quotes in the
metadata of test cases so that those single quotes did not yield
invalid Lua strings in the output of the tester.
It turns out we also need to escape backslashes for things to work
properly. Backslashes also have special meaning within Lua strings.
Found while running the NetBSD test suite. In particular, the
lib/libc/gen/t_fnmatch test program had the '\'' sequence in the
description of a test and this made the test program be reported
as bogus.
To generate a diff of this commit:
cvs rdiff -u -r1.1.1.1 -r1.2 src/external/bsd/kyua-testers/dist/atf_list.c \
src/external/bsd/kyua-testers/dist/atf_list_test.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/external/bsd/kyua-testers/dist/atf_list.c
diff -u src/external/bsd/kyua-testers/dist/atf_list.c:1.1.1.1 src/external/bsd/kyua-testers/dist/atf_list.c:1.2
--- src/external/bsd/kyua-testers/dist/atf_list.c:1.1.1.1 Tue Feb 19 06:01:39 2013
+++ src/external/bsd/kyua-testers/dist/atf_list.c Sat Feb 23 21:04:28 2013
@@ -111,6 +111,26 @@ parse_header(FILE* input)
}
+/// Looks for the first occurrence of any of the specified delimiters.
+///
+/// \param container String in which to look for the delimiters.
+/// \param delimiters List of delimiters to look for.
+///
+/// \return A pointer to the first occurrence of the delimiter, or NULL if
+/// there is none.
+static char*
+find_first_of(char* container, const char* delimiters)
+{
+ char* ptr = container;
+ while (*ptr != '\0') {
+ if (strchr(delimiters, *ptr) != NULL)
+ return ptr;
+ ++ptr;
+ }
+ return NULL;
+}
+
+
/// Prints a string within single quotes, with proper escaping.
///
/// \param [in,out] line The line to be printed. This is a non-const pointer
@@ -120,15 +140,17 @@ parse_header(FILE* input)
static void
print_quoted(char* line, FILE* output, const bool surrounding)
{
- char* quote;
-
if (surrounding)
fprintf(output, "'");
- while ((quote = strchr(line, '\'')) != NULL) {
- *quote = '\0';
- fprintf(output, "%s\\'", line);
- line = quote + 1;
+
+ char* quoteptr;
+ while ((quoteptr = find_first_of(line, "\'\\")) != NULL) {
+ const char quote = *quoteptr;
+ *quoteptr = '\0';
+ fprintf(output, "%s\\%c", line, quote);
+ line = quoteptr + 1;
}
+
if (surrounding)
fprintf(output, "%s'", line);
else
Index: src/external/bsd/kyua-testers/dist/atf_list_test.c
diff -u src/external/bsd/kyua-testers/dist/atf_list_test.c:1.1.1.1 src/external/bsd/kyua-testers/dist/atf_list_test.c:1.2
--- src/external/bsd/kyua-testers/dist/atf_list_test.c:1.1.1.1 Tue Feb 19 06:01:39 2013
+++ src/external/bsd/kyua-testers/dist/atf_list_test.c Sat Feb 23 21:04:28 2013
@@ -127,7 +127,7 @@ ATF_TC_BODY(parse__ok__several, tc)
"ident: second\n"
"\n"
"ident: third\n"
- "descr: A string with an embedded ' in it\n"
+ "descr: A string with an embedded ' and \\' in it\n"
"has.cleanup: true\n"
"X-custom: foo\n"
"X-a'b: bar\n");
@@ -135,8 +135,8 @@ ATF_TC_BODY(parse__ok__several, tc)
"input.txt",
"test_case{name='first', required_user='root'}\n"
"test_case{name='second'}\n"
- "test_case{name='third', description='A string with an embedded \\' in"
- " it', has_cleanup='true', ['custom.X-custom']='foo', "
+ "test_case{name='third', description='A string with an embedded \\' "
+ "and \\\\\\' in it', has_cleanup='true', ['custom.X-custom']='foo', "
"['custom.X-a\\'b']='bar'}\n");
}