fix: unicode problems on chinese systems with single-char chinese strings

This commit is contained in:
Massimo Melina 2020-06-02 12:50:49 +02:00
parent 60c7674dc5
commit b4ca9f113a

View File

@ -334,6 +334,7 @@ uses
Windows, ansistrings; Windows, ansistrings;
const const
CRLF = #13#10; CRLF = #13#10;
HEADER_LIMITER: ansistring = CRLF+CRLF;
MAX_REQUEST_LENGTH = 64*1024; MAX_REQUEST_LENGTH = 64*1024;
MAX_INPUT_BUFFER_LENGTH = 256*1024; MAX_INPUT_BUFFER_LENGTH = 256*1024;
// used as body content when the user did not specify any // used as body content when the user did not specify any
@ -672,7 +673,7 @@ end; // chopline
function chopLine(var s:ansistring):ansistring; overload; function chopLine(var s:ansistring):ansistring; overload;
begin begin
result:=chop(pos(#10,s),1,s); result:=chop(#10,s);
if (result>'') and (result[length(result)]=#13) then if (result>'') and (result[length(result)]=#13) then
setlength(result, length(result)-1); setlength(result, length(result)-1);
end; // chopline end; // chopline
@ -1209,8 +1210,8 @@ procedure ThttpConn.processInputBuffer();
var var
i: integer; i: integer;
s, l, k, c: string; s, l, k, v: ansistring;
ws: widestring;
begin begin
repeat repeat
{ When the buffer is stuffed with file bytes only, we can avoid calling pos() and chop(). { When the buffer is stuffed with file bytes only, we can avoid calling pos() and chop().
@ -1251,11 +1252,12 @@ procedure ThttpConn.processInputBuffer();
break; break;
end; end;
// we wait for the header to be complete // we wait for the header to be complete
if posEx(CRLF+CRLF, buffer, i+length(post.boundary)) = 0 then break; if posEx(HEADER_LIMITER, buffer, i+length(post.boundary)) = 0 then
break;
handleLeftData(i); handleLeftData(i);
post.filename:=''; post.filename:='';
post.data:=''; post.data:='';
post.header:=chop(CRLF+CRLF, buffer); post.header:=chop(HEADER_LIMITER, buffer);
chopLine(post.header); chopLine(post.header);
// parse the header part // parse the header part
s:=post.header; s:=post.header;
@ -1264,25 +1266,28 @@ procedure ThttpConn.processInputBuffer();
l:=chopLine(s); l:=chopLine(s);
if l = '' then continue; if l = '' then continue;
k:=chop(':', l); k:=chop(':', l);
if not sameText(k, 'Content-Disposition') then continue; // we are not interested in other fields if not sameText(k, 'Content-Disposition') then // we are only interested in content-disposition: form-data
continue;
k:=trim(chop(';', l)); k:=trim(chop(';', l));
if not sameText(k, 'form-data') then continue; if not sameText(k, 'form-data') then
continue;
while l > '' do while l > '' do
begin begin
c:=chop(nonQuotedPos(';', l), l); v:=chop(nonQuotedPos(';', l), 1, l);
k:=UTF8toString(rawByteString(trim(chop('=', c)))); k:=trim(chop('=', v));
c:=UTF8toString(rawByteString(ansiDequotedStr(c,'"'))); ws:=UTF8toString(ansiDequotedStr(v,'"'));
if sameText(k, 'filename') then if sameText(k, 'filename') then
begin begin
delete(c, 1, lastDelimiter('/\',c)); delete(ws, 1, lastDelimiter('/\',ws));
post.filename:=c; post.filename:=ws;
end; end
if sameText(k, 'name') then else if sameText(k, 'name') then
post.varname:=c; post.varname:=ws;
end; end;
end; end;
lastPostItemPos:=bytesPosted-length(buffer); lastPostItemPos:=bytesPosted-length(buffer);
if post.filename = '' then continue; if post.filename = '' then
continue;
firstPostFile:=FALSE; firstPostFile:=FALSE;
tryNotify(HE_POST_FILE); tryNotify(HE_POST_FILE);
until false; until false;