mirror of https://github.com/aria2/aria2
Made return type of util::parse_content_disposition ssize_t
parent
7db480b024
commit
31189b1222
|
@ -891,7 +891,7 @@ typedef enum {
|
|||
CD_ENC_ISO_8859_1
|
||||
} content_disposition_charset;
|
||||
|
||||
int parse_content_disposition(char *dest, size_t destlen,
|
||||
ssize_t parse_content_disposition(char *dest, size_t destlen,
|
||||
const char **charsetp, size_t *charsetlenp,
|
||||
const char *in, size_t len)
|
||||
{
|
||||
|
@ -1189,7 +1189,8 @@ std::string getContentDispositionFilename(const std::string& header)
|
|||
size_t cdvallen = sizeof(cdval);
|
||||
const char* charset;
|
||||
size_t charsetlen;
|
||||
int rv = parse_content_disposition(cdval, cdvallen, &charset, &charsetlen,
|
||||
ssize_t rv = parse_content_disposition(cdval, cdvallen,
|
||||
&charset, &charsetlen,
|
||||
header.c_str(), header.size());
|
||||
if(rv == -1) {
|
||||
return "";
|
||||
|
|
|
@ -312,7 +312,7 @@ std::string iso8859p1ToUtf8(const std::string& src);
|
|||
// succeeds, or -1. If there is enough room to store filename in
|
||||
// |dest|, this function returns -1. If this function returns -1, the
|
||||
// |dest|, |*charsetp| and |*charsetlenp| are undefined.
|
||||
int parse_content_disposition(char *dest, size_t destlen,
|
||||
ssize_t parse_content_disposition(char *dest, size_t destlen,
|
||||
const char **charsetp, size_t *charsetlenp,
|
||||
const char *in, size_t len);
|
||||
|
||||
|
|
182
test/UtilTest.cc
182
test/UtilTest.cc
|
@ -896,121 +896,121 @@ void UtilTest::testParseContentDisposition() {
|
|||
// test cases from http://greenbytes.de/tech/tc2231/
|
||||
// inlonly
|
||||
val = "inline";
|
||||
CPPUNIT_ASSERT_EQUAL(0, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)0, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
|
||||
// inlonlyquoted
|
||||
val = "\"inline\"";
|
||||
CPPUNIT_ASSERT_EQUAL(-1, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
|
||||
// inlwithasciifilename
|
||||
val = "inline; filename=\"foo.html\"";
|
||||
CPPUNIT_ASSERT_EQUAL(8, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)8, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("foo.html"),
|
||||
std::string(&dest[0], &dest[8]));
|
||||
|
||||
// inlwithfnattach
|
||||
val = "inline; filename=\"Not an attachment!\"";
|
||||
CPPUNIT_ASSERT_EQUAL(18, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)18, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("Not an attachment!"),
|
||||
std::string(&dest[0], &dest[18]));
|
||||
|
||||
// inlwithasciifilenamepdf
|
||||
val = "inline; filename=\"foo.pdf\"";
|
||||
CPPUNIT_ASSERT_EQUAL(7, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)7, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("foo.pdf"),
|
||||
std::string(&dest[0], &dest[7]));
|
||||
|
||||
// attwithasciifilename25
|
||||
val = "attachment; filename=\"0000000000111111111122222\"";
|
||||
CPPUNIT_ASSERT_EQUAL(25, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)25, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("0000000000111111111122222"),
|
||||
std::string(&dest[0], &dest[25]));
|
||||
|
||||
// attwithasciifilename35
|
||||
val = "attachment; filename=\"00000000001111111111222222222233333\"";
|
||||
CPPUNIT_ASSERT_EQUAL(35, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)35, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("00000000001111111111222222222233333"),
|
||||
std::string(&dest[0], &dest[35]));
|
||||
|
||||
// attwithasciifnescapedchar
|
||||
val = "attachment; filename=\"f\\oo.html\"";
|
||||
CPPUNIT_ASSERT_EQUAL(8, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)8, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("foo.html"),
|
||||
std::string(&dest[0], &dest[8]));
|
||||
|
||||
// attwithasciifnescapedquote
|
||||
val = "attachment; filename=\"\\\"quoting\\\" tested.html\"";
|
||||
CPPUNIT_ASSERT_EQUAL(21, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)21, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("\"quoting\" tested.html"),
|
||||
std::string(&dest[0], &dest[21]));
|
||||
|
||||
// attwithquotedsemicolon
|
||||
val = "attachment; filename=\"Here's a semicolon;.html\"";
|
||||
CPPUNIT_ASSERT_EQUAL(24, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)24, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("Here's a semicolon;.html"),
|
||||
std::string(&dest[0], &dest[24]));
|
||||
|
||||
// attwithfilenameandextparam
|
||||
val = "attachment; foo=\"bar\"; filename=\"foo.html\"";
|
||||
CPPUNIT_ASSERT_EQUAL(8, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)8, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("foo.html"),
|
||||
std::string(&dest[0], &dest[8]));
|
||||
|
||||
// attwithfilenameandextparamescaped
|
||||
val = "attachment; foo=\"\\\"\\\\\";filename=\"foo.html\"";
|
||||
CPPUNIT_ASSERT_EQUAL(8, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)8, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("foo.html"),
|
||||
std::string(&dest[0], &dest[8]));
|
||||
|
||||
// attwithasciifilenameucase
|
||||
val = "attachment; FILENAME=\"foo.html\"";
|
||||
CPPUNIT_ASSERT_EQUAL(8, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)8, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("foo.html"),
|
||||
std::string(&dest[0], &dest[8]));
|
||||
|
||||
// attwithasciifilenamenq
|
||||
val = "attachment; filename=foo.html";
|
||||
CPPUNIT_ASSERT_EQUAL(8, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)8, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("foo.html"),
|
||||
std::string(&dest[0], &dest[8]));
|
||||
|
||||
// attwithtokfncommanq
|
||||
val = "attachment; filename=foo,bar.html";
|
||||
CPPUNIT_ASSERT_EQUAL(-1, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
|
||||
// attwithasciifilenamenqs
|
||||
val = "attachment; filename=foo.html ;";
|
||||
CPPUNIT_ASSERT_EQUAL(-1, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
|
||||
// attemptyparam
|
||||
val = "attachment; ;filename=foo";
|
||||
CPPUNIT_ASSERT_EQUAL(-1, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
|
||||
// attwithasciifilenamenqws
|
||||
val = "attachment; filename=foo bar.html";
|
||||
CPPUNIT_ASSERT_EQUAL(-1, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
|
||||
// attwithfntokensq
|
||||
val = "attachment; filename='foo.bar'";
|
||||
CPPUNIT_ASSERT_EQUAL(9, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)9, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("'foo.bar'"),
|
||||
std::string(&dest[0], &dest[9]));
|
||||
|
@ -1019,7 +1019,7 @@ void UtilTest::testParseContentDisposition() {
|
|||
// attachment; filename="foo-ä.html"
|
||||
val = "attachment; filename=\"foo-%E4.html\"";
|
||||
val = util::percentDecode(val.begin(), val.end());
|
||||
CPPUNIT_ASSERT_EQUAL(10, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)10, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("foo-ä.html"),
|
||||
util::iso8859p1ToUtf8(std::string(&dest[0], &dest[10])));
|
||||
|
@ -1028,199 +1028,199 @@ void UtilTest::testParseContentDisposition() {
|
|||
// attachment; filename="foo-ä.html"
|
||||
val = "attachment; filename=\"foo-%C3%A4.html\"";
|
||||
val = util::percentDecode(val.begin(), val.end());
|
||||
CPPUNIT_ASSERT_EQUAL(11, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)11, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("foo-ä.html"),
|
||||
util::iso8859p1ToUtf8(std::string(&dest[0], &dest[11])));
|
||||
|
||||
// attwithfnrawpctenca
|
||||
val = "attachment; filename=\"foo-%41.html\"";
|
||||
CPPUNIT_ASSERT_EQUAL(12, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)12, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("foo-%41.html"),
|
||||
std::string(&dest[0], &dest[12]));
|
||||
|
||||
// attwithfnusingpct
|
||||
val = "attachment; filename=\"50%.html\"";
|
||||
CPPUNIT_ASSERT_EQUAL(8, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)8, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("50%.html"),
|
||||
std::string(&dest[0], &dest[8]));
|
||||
|
||||
// attwithfnrawpctencaq
|
||||
val = "attachment; filename=\"foo-%\\41.html\"";
|
||||
CPPUNIT_ASSERT_EQUAL(12, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)12, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("foo-%41.html"),
|
||||
std::string(&dest[0], &dest[12]));
|
||||
|
||||
// attwithnamepct
|
||||
val = "attachment; name=\"foo-%41.html\"";
|
||||
CPPUNIT_ASSERT_EQUAL(0, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)0, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
|
||||
// attwithfilenamepctandiso
|
||||
// attachment; filename="ä-%41.html"
|
||||
val = "attachment; filename=\"%E4-%2541.html\"";
|
||||
val = util::percentDecode(val.begin(), val.end());
|
||||
CPPUNIT_ASSERT_EQUAL(10, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)10, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("ä-%41.html"),
|
||||
util::iso8859p1ToUtf8(std::string(&dest[0], &dest[10])));
|
||||
|
||||
// attwithfnrawpctenclong
|
||||
val = "attachment; filename=\"foo-%c3%a4-%e2%82%ac.html\"";
|
||||
CPPUNIT_ASSERT_EQUAL(25, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)25, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("foo-%c3%a4-%e2%82%ac.html"),
|
||||
std::string(&dest[0], &dest[25]));
|
||||
|
||||
// attwithasciifilenamews1
|
||||
val = "attachment; filename =\"foo.html\"";
|
||||
CPPUNIT_ASSERT_EQUAL(8, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)8, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("foo.html"),
|
||||
std::string(&dest[0], &dest[8]));
|
||||
|
||||
// attwith2filenames
|
||||
val = "attachment; filename=\"foo.html\"; filename=\"bar.html\"";
|
||||
CPPUNIT_ASSERT_EQUAL(-1, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
|
||||
// attfnbrokentoken
|
||||
val = "attachment; filename=foo[1](2).html";
|
||||
CPPUNIT_ASSERT_EQUAL(-1, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
|
||||
// attfnbrokentokeniso
|
||||
val = "attachment; filename=foo-%E4.html";
|
||||
val = util::percentDecode(val.begin(), val.end());
|
||||
CPPUNIT_ASSERT_EQUAL(-1, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
|
||||
// attfnbrokentokenutf
|
||||
// attachment; filename=foo-ä.html
|
||||
val = "attachment; filename=foo-ä.html";
|
||||
CPPUNIT_ASSERT_EQUAL(-1, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
|
||||
// attmissingdisposition
|
||||
val = "filename=foo.html";
|
||||
CPPUNIT_ASSERT_EQUAL(-1, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
|
||||
// attmissingdisposition2
|
||||
val = "x=y; filename=foo.html";
|
||||
CPPUNIT_ASSERT_EQUAL(-1, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
|
||||
// attmissingdisposition3
|
||||
val = "\"foo; filename=bar;baz\"; filename=qux";
|
||||
CPPUNIT_ASSERT_EQUAL(-1, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
|
||||
// attmissingdisposition4
|
||||
val = "filename=foo.html, filename=bar.html";
|
||||
CPPUNIT_ASSERT_EQUAL(-1, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
|
||||
// emptydisposition
|
||||
val = "; filename=foo.html";
|
||||
CPPUNIT_ASSERT_EQUAL(-1, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
|
||||
// doublecolon
|
||||
val = ": inline; attachment; filename=foo.html";
|
||||
CPPUNIT_ASSERT_EQUAL(-1, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
|
||||
// attandinline
|
||||
val = "inline; attachment; filename=foo.html";
|
||||
CPPUNIT_ASSERT_EQUAL(-1, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
|
||||
// attandinline2
|
||||
val = "attachment; inline; filename=foo.html";
|
||||
CPPUNIT_ASSERT_EQUAL(-1, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
|
||||
// attbrokenquotedfn
|
||||
val = "attachment; filename=\"foo.html\".txt";
|
||||
CPPUNIT_ASSERT_EQUAL(-1, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
|
||||
// attbrokenquotedfn2
|
||||
val = "attachment; filename=\"bar";
|
||||
CPPUNIT_ASSERT_EQUAL(-1, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
|
||||
// attbrokenquotedfn3
|
||||
val = "attachment; filename=foo\"bar;baz\"qux";
|
||||
CPPUNIT_ASSERT_EQUAL(-1, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
|
||||
// attmultinstances
|
||||
val = "attachment; filename=foo.html, attachment; filename=bar.html";
|
||||
CPPUNIT_ASSERT_EQUAL(-1, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
|
||||
// attmissingdelim
|
||||
val = "attachment; foo=foo filename=bar";
|
||||
CPPUNIT_ASSERT_EQUAL(-1, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
|
||||
// attmissingdelim2
|
||||
val = "attachment; filename=bar foo=foo ";
|
||||
CPPUNIT_ASSERT_EQUAL(-1, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
|
||||
// attmissingdelim3
|
||||
val = "attachment filename=bar";
|
||||
CPPUNIT_ASSERT_EQUAL(-1, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
|
||||
// attreversed
|
||||
val = "filename=foo.html; attachment";
|
||||
CPPUNIT_ASSERT_EQUAL(-1, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
|
||||
// attconfusedparam
|
||||
val = "attachment; xfilename=foo.html";
|
||||
CPPUNIT_ASSERT_EQUAL(0, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)0, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
|
||||
// attabspath
|
||||
val = "attachment; filename=\"/foo.html\"";
|
||||
CPPUNIT_ASSERT_EQUAL(9, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)9, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("/foo.html"),
|
||||
std::string(&dest[0], &dest[9]));
|
||||
|
||||
// attabspathwin
|
||||
val = "attachment; filename=\"\\\\foo.html\"";
|
||||
CPPUNIT_ASSERT_EQUAL(9, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)9, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("\\foo.html"),
|
||||
std::string(&dest[0], &dest[9]));
|
||||
|
||||
// attcdate
|
||||
val = "attachment; creation-date=\"Wed, 12 Feb 1997 16:29:51 -0500\"";
|
||||
CPPUNIT_ASSERT_EQUAL(0, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)0, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
|
||||
// dispext
|
||||
val = "foobar";
|
||||
CPPUNIT_ASSERT_EQUAL(0, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)0, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
|
||||
// dispextbadfn
|
||||
val = "attachment; example=\"filename=example.txt\"";
|
||||
CPPUNIT_ASSERT_EQUAL(0, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)0, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
|
||||
// attwithisofn2231iso
|
||||
val = "attachment; filename*=iso-8859-1''foo-%E4.html";
|
||||
CPPUNIT_ASSERT_EQUAL(10, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)10, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("iso-8859-1"), std::string(cs, cslen));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("foo-ä.html"),
|
||||
|
@ -1228,7 +1228,7 @@ void UtilTest::testParseContentDisposition() {
|
|||
|
||||
// attwithfn2231utf8
|
||||
val = "attachment; filename*=UTF-8''foo-%c3%a4-%e2%82%ac.html";
|
||||
CPPUNIT_ASSERT_EQUAL(15, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)15, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("UTF-8"), std::string(cs, cslen));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("foo-ä-€.html"),
|
||||
|
@ -1236,12 +1236,12 @@ void UtilTest::testParseContentDisposition() {
|
|||
|
||||
// attwithfn2231noc
|
||||
val = "attachment; filename*=''foo-%c3%a4-%e2%82%ac.html";
|
||||
CPPUNIT_ASSERT_EQUAL(-1, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
|
||||
// attwithfn2231utf8comp
|
||||
val = "attachment; filename*=UTF-8''foo-a%cc%88.html";
|
||||
CPPUNIT_ASSERT_EQUAL(12, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)12, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
val = "foo-a%cc%88.html";
|
||||
CPPUNIT_ASSERT_EQUAL(std::string(util::percentDecode(val.begin(),
|
||||
|
@ -1250,89 +1250,89 @@ void UtilTest::testParseContentDisposition() {
|
|||
|
||||
// attwithfn2231utf8-bad
|
||||
val = "attachment; filename*=iso-8859-1''foo-%c3%a4-%e2%82%ac.html";
|
||||
CPPUNIT_ASSERT_EQUAL(-1, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
|
||||
// attwithfn2231iso-bad
|
||||
val = "attachment; filename*=utf-8''foo-%E4.html";
|
||||
CPPUNIT_ASSERT_EQUAL(-1, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
|
||||
// attwithfn2231ws1
|
||||
val = "attachment; filename *=UTF-8''foo-%c3%a4.html";
|
||||
CPPUNIT_ASSERT_EQUAL(-1, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
|
||||
// attwithfn2231ws2
|
||||
val = "attachment; filename*= UTF-8''foo-%c3%a4.html";
|
||||
CPPUNIT_ASSERT_EQUAL(11, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)11, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("foo-ä.html"),
|
||||
std::string(&dest[0], &dest[11]));
|
||||
|
||||
// attwithfn2231ws3
|
||||
val = "attachment; filename* =UTF-8''foo-%c3%a4.html";
|
||||
CPPUNIT_ASSERT_EQUAL(11, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)11, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("foo-ä.html"),
|
||||
std::string(&dest[0], &dest[11]));
|
||||
|
||||
// attwithfn2231quot
|
||||
val = "attachment; filename*=\"UTF-8''foo-%c3%a4.html\"";
|
||||
CPPUNIT_ASSERT_EQUAL(-1, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
|
||||
// attwithfn2231quot2
|
||||
val = "attachment; filename*=\"foo%20bar.html\"";
|
||||
CPPUNIT_ASSERT_EQUAL(-1, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
|
||||
// attwithfn2231singleqmissing
|
||||
val = "attachment; filename*=UTF-8'foo-%c3%a4.html";
|
||||
CPPUNIT_ASSERT_EQUAL(-1, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
|
||||
// attwithfn2231nbadpct1
|
||||
val = "attachment; filename*=UTF-8''foo%";
|
||||
CPPUNIT_ASSERT_EQUAL(-1, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
|
||||
// attwithfn2231nbadpct2
|
||||
val = "attachment; filename*=UTF-8''f%oo.html";
|
||||
CPPUNIT_ASSERT_EQUAL(-1, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
|
||||
// attwithfn2231dpct
|
||||
val = "attachment; filename*=UTF-8''A-%2541.html";
|
||||
CPPUNIT_ASSERT_EQUAL(10, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)10, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("A-%41.html"),
|
||||
std::string(&dest[0], &dest[10]));
|
||||
|
||||
// attwithfn2231abspathdisguised
|
||||
val = "attachment; filename*=UTF-8''%5cfoo.html";
|
||||
CPPUNIT_ASSERT_EQUAL(9, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)9, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("\\foo.html"),
|
||||
std::string(&dest[0], &dest[9]));
|
||||
|
||||
// attfnboth
|
||||
val = "attachment; filename=\"foo-ae.html\"; filename*=UTF-8''foo-%c3%a4.html";
|
||||
CPPUNIT_ASSERT_EQUAL(11, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)11, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("foo-ä.html"),
|
||||
std::string(&dest[0], &dest[11]));
|
||||
|
||||
// attfnboth2
|
||||
val = "attachment; filename*=UTF-8''foo-%c3%a4.html; filename=\"foo-ae.html\"";
|
||||
CPPUNIT_ASSERT_EQUAL(11, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)11, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("foo-ä.html"),
|
||||
std::string(&dest[0], &dest[11]));
|
||||
|
||||
// attfnboth3
|
||||
val = "attachment; filename*0*=ISO-8859-15''euro-sign%3d%a4; filename*=ISO-8859-1''currency-sign%3d%a4";
|
||||
CPPUNIT_ASSERT_EQUAL(15, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)15, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("ISO-8859-1"), std::string(cs, cslen));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("currency-sign=¤"),
|
||||
|
@ -1340,19 +1340,19 @@ void UtilTest::testParseContentDisposition() {
|
|||
|
||||
// attnewandfn
|
||||
val = "attachment; foobar=x; filename=\"foo.html\"";
|
||||
CPPUNIT_ASSERT_EQUAL(8, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)8, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("foo.html"),
|
||||
std::string(&dest[0], &dest[8]));
|
||||
|
||||
// attrfc2047token
|
||||
val = "attachment; filename==?ISO-8859-1?Q?foo-=E4.html?=";
|
||||
CPPUNIT_ASSERT_EQUAL(-1, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
|
||||
// attrfc2047quoted
|
||||
val = "attachment; filename=\"=?ISO-8859-1?Q?foo-=E4.html?=\"";
|
||||
CPPUNIT_ASSERT_EQUAL(29, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)29, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("=?ISO-8859-1?Q?foo-=E4.html?="),
|
||||
std::string(&dest[0], &dest[29]));
|
||||
|
@ -1361,90 +1361,90 @@ void UtilTest::testParseContentDisposition() {
|
|||
|
||||
// zero-length filename. token cannot be empty, so this is invalid.
|
||||
val = "attachment; filename=";
|
||||
CPPUNIT_ASSERT_EQUAL(-1, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
|
||||
// zero-length filename. quoted-string can be empty string, so this
|
||||
// is ok.
|
||||
val = "attachment; filename=\"\"";
|
||||
CPPUNIT_ASSERT_EQUAL(0, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)0, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
|
||||
// empty value is not allowed
|
||||
val = "attachment; filename=;";
|
||||
CPPUNIT_ASSERT_EQUAL(-1, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
|
||||
// / is not valid char in token.
|
||||
val = "attachment; filename=dir/file";
|
||||
CPPUNIT_ASSERT_EQUAL(-1, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
|
||||
// value-chars is *(pct-encoded / attr-char), so empty string is
|
||||
// allowed.
|
||||
val = "attachment; filename*=UTF-8''";
|
||||
CPPUNIT_ASSERT_EQUAL(0, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)0, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("UTF-8"), std::string(cs, cslen));
|
||||
|
||||
val = "attachment; filename*=UTF-8''; filename=foo";
|
||||
CPPUNIT_ASSERT_EQUAL(0, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)0, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("UTF-8"), std::string(cs, cslen));
|
||||
|
||||
val = "attachment; filename*=UTF-8'' ; filename=foo";
|
||||
CPPUNIT_ASSERT_EQUAL(0, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)0, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("UTF-8"), std::string(cs, cslen));
|
||||
|
||||
// with language
|
||||
val = "attachment; filename*=UTF-8'japanese'konnichiwa";
|
||||
CPPUNIT_ASSERT_EQUAL(10, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)10, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("konnichiwa"),
|
||||
std::string(&dest[0], &dest[10]));
|
||||
|
||||
// lws before and after "="
|
||||
val = "attachment; filename = foo.html";
|
||||
CPPUNIT_ASSERT_EQUAL(8, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)8, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("foo.html"),
|
||||
std::string(&dest[0], &dest[8]));
|
||||
|
||||
// lws before and after "=" with quoted-string
|
||||
val = "attachment; filename = \"foo.html\"";
|
||||
CPPUNIT_ASSERT_EQUAL(8, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)8, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("foo.html"),
|
||||
std::string(&dest[0], &dest[8]));
|
||||
|
||||
// lws after parm
|
||||
val = "attachment; filename=foo.html ";
|
||||
CPPUNIT_ASSERT_EQUAL(8, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)8, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("foo.html"),
|
||||
std::string(&dest[0], &dest[8]));
|
||||
|
||||
val = "attachment; filename=foo.html ; hello=world";
|
||||
CPPUNIT_ASSERT_EQUAL(8, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)8, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("foo.html"),
|
||||
std::string(&dest[0], &dest[8]));
|
||||
|
||||
val = "attachment; filename=\"foo.html\" ";
|
||||
CPPUNIT_ASSERT_EQUAL(8, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)8, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("foo.html"),
|
||||
std::string(&dest[0], &dest[8]));
|
||||
|
||||
val = "attachment; filename=\"foo.html\" ; hello=world";
|
||||
CPPUNIT_ASSERT_EQUAL(8, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)8, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("foo.html"),
|
||||
std::string(&dest[0], &dest[8]));
|
||||
|
||||
val = "attachment; filename*=UTF-8''foo.html ; hello=world";
|
||||
CPPUNIT_ASSERT_EQUAL(8, util::parse_content_disposition
|
||||
CPPUNIT_ASSERT_EQUAL((ssize_t)8, util::parse_content_disposition
|
||||
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("foo.html"),
|
||||
std::string(&dest[0], &dest[8]));
|
||||
|
|
Loading…
Reference in New Issue