Fix CGI form/cookie data handling and CGI URL encode/decode
- CGIFormData: fix broken setSize()+read() double-length bug that corrupted every parsed body with a leading run of garbage bytes (setSize(contentLength) pre-set length before read()/write() appended on top of it); switch content-type checks from exact equality to startsWith() since a real multipart Content-Type always carries a boundary= parameter; implement the previously empty multipart/form-data branch (ordinary fields only, file uploads deferred to a separate upload mechanism per TODO.txt); restore operator[] real lookup logic (was hardcoded to echo the key back); default-initialize formdata to NULL; fix mismatched include guard (leftover from an IMFFormData.h copy-paste); drop the unused IMFHeader.h include that pulled in a broken, unrelated StreamReader.h dependency. - CGIFormattedData: parameterize the split delimiter (was hardcoded to &, which silently broke cookie parsing since HTTP_COOKIE uses ; not &) and trim whitespace on each split token. - MString::toCGI()/fromCGI(): were unimplemented stubs (always returned an empty string); implemented proper CGI percent-encode / percent-decode + space plus-encoding, and fixed the one caller that discarded fromCGIs return value instead of using it. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
28feaff3d7
commit
94d4a30e88
5 files changed
+121
-34
No files matched your search
+22
-16
@@ -4,27 +4,33 @@
|
||||
namespace coreutils {
|
||||
|
||||
CGIFormattedData::CGIFormattedData() {}
|
||||
|
||||
|
||||
CGIFormattedData::CGIFormattedData(ZString cgiData) {
|
||||
if(cgiData != "") {
|
||||
cgiData.split("&");
|
||||
parse(cgiData);
|
||||
}
|
||||
|
||||
CGIFormattedData::CGIFormattedData(ZString cgiData, ZString delimiter) : delimiter(delimiter) {
|
||||
parse(cgiData);
|
||||
}
|
||||
|
||||
void CGIFormattedData::setDelimiter(ZString delimiter) {
|
||||
this->delimiter = delimiter;
|
||||
}
|
||||
|
||||
void CGIFormattedData::parse(ZString cgiData) {
|
||||
if(cgiData != "") {
|
||||
cgiData.split(delimiter);
|
||||
for(int ix = 0; ix < cgiData.getList().size(); ++ix) {
|
||||
cgiData[ix].split("=");
|
||||
data[cgiData[ix][0]] = cgiData[ix][1];
|
||||
data[cgiData[ix][0]].fromCGI();
|
||||
ZString pair = cgiData[ix].trim();
|
||||
pair.split("=");
|
||||
data[pair[0]] = pair[1];
|
||||
data[pair[0]] = data[pair[0]].fromCGI();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ZString CGIFormattedData::operator=(ZString cgiData) {
|
||||
if(cgiData != "") {
|
||||
cgiData.split("&");
|
||||
for(int ix = 0; ix < cgiData.getList().size(); ++ix) {
|
||||
cgiData[ix].split("=");
|
||||
data[cgiData[ix][0]] = cgiData[ix][1];
|
||||
data[cgiData[ix][0]].fromCGI();
|
||||
}
|
||||
}
|
||||
parse(cgiData);
|
||||
return cgiData;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user