Skip to content

Commit

Permalink
fix: unicode problems on chinese systems with single-char chinese str…
Browse files Browse the repository at this point in the history
…ings
  • Loading branch information
rejetto committed Jun 2, 2020
1 parent 60c7674 commit b4ca9f1
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions hslib.pas
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ implementation
Windows, ansistrings;
const
CRLF = #13#10;
HEADER_LIMITER: ansistring = CRLF+CRLF;
MAX_REQUEST_LENGTH = 64*1024;
MAX_INPUT_BUFFER_LENGTH = 256*1024;
// used as body content when the user did not specify any
Expand Down Expand Up @@ -672,7 +673,7 @@ function chopLine(var s:string):string; overload;

function chopLine(var s:ansistring):ansistring; overload;
begin
result:=chop(pos(#10,s),1,s);
result:=chop(#10,s);
if (result>'') and (result[length(result)]=#13) then
setlength(result, length(result)-1);
end; // chopline
Expand Down Expand Up @@ -1209,8 +1210,8 @@ procedure ThttpConn.processInputBuffer();

var
i: integer;
s, l, k, c: string;

s, l, k, v: ansistring;
ws: widestring;
begin
repeat
{ When the buffer is stuffed with file bytes only, we can avoid calling pos() and chop().
Expand Down Expand Up @@ -1251,11 +1252,12 @@ procedure ThttpConn.processInputBuffer();
break;
end;
// 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);
post.filename:='';
post.data:='';
post.header:=chop(CRLF+CRLF, buffer);
post.header:=chop(HEADER_LIMITER, buffer);
chopLine(post.header);
// parse the header part
s:=post.header;
Expand All @@ -1264,25 +1266,28 @@ procedure ThttpConn.processInputBuffer();
l:=chopLine(s);
if l = '' then continue;
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));
if not sameText(k, 'form-data') then continue;
if not sameText(k, 'form-data') then
continue;
while l > '' do
begin
c:=chop(nonQuotedPos(';', l), l);
k:=UTF8toString(rawByteString(trim(chop('=', c))));
c:=UTF8toString(rawByteString(ansiDequotedStr(c,'"')));
v:=chop(nonQuotedPos(';', l), 1, l);
k:=trim(chop('=', v));
ws:=UTF8toString(ansiDequotedStr(v,'"'));
if sameText(k, 'filename') then
begin
delete(c, 1, lastDelimiter('/\',c));
post.filename:=c;
end;
if sameText(k, 'name') then
post.varname:=c;
delete(ws, 1, lastDelimiter('/\',ws));
post.filename:=ws;
end
else if sameText(k, 'name') then
post.varname:=ws;
end;
end;
lastPostItemPos:=bytesPosted-length(buffer);
if post.filename = '' then continue;
if post.filename = '' then
continue;
firstPostFile:=FALSE;
tryNotify(HE_POST_FILE);
until false;
Expand Down

0 comments on commit b4ca9f1

Please sign in to comment.