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