Author: joes Date: Mon May 2 05:28:09 2005 New Revision: 165620 URL: http://svn.apache.org/viewcvs?rev=165620&view=rev Log: Continuation of Max's apreq_quote fixes:
http://marc.theaimsgroup.com/?l=apreq-dev&m=111476725130985&w=2 Submitted by: Max Kellermann Reviewed by: joes Modified: httpd/apreq/trunk/library/t/util.c httpd/apreq/trunk/library/util.c Modified: httpd/apreq/trunk/library/t/util.c URL: http://svn.apache.org/viewcvs/httpd/apreq/trunk/library/t/util.c?rev=165620&r1=165619&r2=165620&view=diff ============================================================================== --- httpd/apreq/trunk/library/t/util.c (original) +++ httpd/apreq/trunk/library/t/util.c Mon May 2 05:28:09 2005 @@ -173,9 +173,13 @@ AT_int_eq(len, 7); AT_str_eq(dst, "\"\\\"foo\""); + len = apreq_quote(dst, "foo\\bar", 7); + AT_int_eq(len, 10); + AT_str_eq(dst, "\"foo\\\\bar\""); + len = apreq_quote(dst, "foo\0bar", 7); - AT_int_eq(len, 9); - AT_mem_eq(dst, "\"foo\0bar\"", len + 1); + AT_int_eq(len, 10); + AT_str_eq(dst, "\"foo\\0bar\""); } static void test_quote_once(dAT) @@ -196,12 +200,14 @@ AT_str_eq(dst, "\"foo\\\"\""); len = apreq_quote_once(dst, "foo\0bar", 7); - AT_int_eq(len, 9); - AT_mem_eq(dst, "\"foo\0bar\"", len + 1); + AT_int_eq(len, 10); + AT_str_eq(dst, "\"foo\\0bar\""); + /* null byte must be escaped, even when there are already double + quotes */ len = apreq_quote_once(dst, "\"foo\0bar\"", 9); - AT_int_eq(len, 9); - AT_mem_eq(dst, "\"foo\0bar\"", len + 1); + AT_int_eq(len, 14); + AT_str_eq(dst, "\"\\\"foo\\0bar\\\"\""); len = apreq_quote_once(dst, "\"foo\"", 5); AT_int_eq(len, 5); @@ -211,9 +217,9 @@ AT_int_eq(len, 7); AT_str_eq(dst, "\"'foo'\""); - len = apreq_quote_once(dst, "\"foo\"", 5); - AT_int_eq(len, 5); - AT_str_eq(dst, "\"foo\""); + len = apreq_quote_once(dst, "\"fo\\o\"", 6); + AT_int_eq(len, 6); + AT_str_eq(dst, "\"fo\\o\""); len = apreq_quote_once(dst, "\"foo\"bar\"", 9); AT_int_eq(len, 14); @@ -265,7 +271,7 @@ { dT(test_decodev, 6) }, { dT(test_encode, 0) }, { dT(test_cp1252_to_utf8, 14) }, - { dT(test_quote, 6) }, + { dT(test_quote, 8) }, { dT(test_quote_once, 18), }, { dT(test_join, 0) }, { dT(test_brigade_fwrite, 0) }, Modified: httpd/apreq/trunk/library/util.c URL: http://svn.apache.org/viewcvs/httpd/apreq/trunk/library/util.c?rev=165620&r1=165619&r2=165620&view=diff ============================================================================== --- httpd/apreq/trunk/library/util.c (original) +++ httpd/apreq/trunk/library/util.c Mon May 2 05:28:09 2005 @@ -676,7 +676,7 @@ for (i = 1; i < len - 1; i++) { if (p[i] == '\\') backslash = !backslash; - else if (p[i] == '"' && !backslash) + else if (p[i] == 0 || (p[i] == '"' && !backslash)) return 0; else backslash = 0; @@ -716,21 +716,20 @@ *d++ = '"'; while (s <= last) { - switch (*s) { + case 0: + *d++ = '\\'; + *d++ = '0'; + s++; + break; case '\\': - if (s < last) { - *d++ = *s++; - break; - } - /* else fall through */ - case '"': *d++ = '\\'; - } - *d++ = *s++; + default: + *d++ = *s++; + } } *d++ = '"';
