Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/external/bsd/kyua-testers/dist Cherry-pick upstream commit 9...



details:   https://anonhg.NetBSD.org/src/rev/4d824000b555
branches:  trunk
changeset: 785111:4d824000b555
user:      jmmv <jmmv%NetBSD.org@localhost>
date:      Sat Feb 23 21:04:28 2013 +0000

description:
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.

diffstat:

 external/bsd/kyua-testers/dist/atf_list.c      |  34 +++++++++++++++++++++----
 external/bsd/kyua-testers/dist/atf_list_test.c |   6 ++--
 2 files changed, 31 insertions(+), 9 deletions(-)

diffs (77 lines):

diff -r d5fc5667cf86 -r 4d824000b555 external/bsd/kyua-testers/dist/atf_list.c
--- a/external/bsd/kyua-testers/dist/atf_list.c Sat Feb 23 16:22:38 2013 +0000
+++ b/external/bsd/kyua-testers/dist/atf_list.c Sat Feb 23 21:04:28 2013 +0000
@@ -111,6 +111,26 @@
 }
 
 
+/// 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 @@
 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
diff -r d5fc5667cf86 -r 4d824000b555 external/bsd/kyua-testers/dist/atf_list_test.c
--- a/external/bsd/kyua-testers/dist/atf_list_test.c    Sat Feb 23 16:22:38 2013 +0000
+++ b/external/bsd/kyua-testers/dist/atf_list_test.c    Sat Feb 23 21:04:28 2013 +0000
@@ -127,7 +127,7 @@
         "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 @@
         "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");
 }
 



Home | Main Index | Thread Index | Old Index