mirror of
https://github.com/rejetto/hfs2.git
synced 2025-12-19 18:13:46 +01:00
fix: utf-8 decoding for {.load.}
This commit is contained in:
parent
469acc3fb7
commit
df5fa09ba9
@ -1366,7 +1366,7 @@ if buffer = '' then exit;
|
||||
if state = HCS_IDLE then
|
||||
begin
|
||||
state:=HCS_REQUESTING;
|
||||
reply.contentType:='text/html';
|
||||
reply.contentType:='text/html; charset=utf-8';
|
||||
notify(HE_REQUESTING);
|
||||
end;
|
||||
case state of
|
||||
@ -1384,7 +1384,7 @@ notify(HE_REQUESTED);
|
||||
if not initInputStream() then
|
||||
begin
|
||||
reply.mode:=HRM_INTERNAL_ERROR;
|
||||
reply.contentType:='text/html';
|
||||
reply.contentType:='text/html; charset=utf-8';
|
||||
notify(HE_CANT_OPEN_FILE);
|
||||
end;
|
||||
notify(HE_STREAM_READY);
|
||||
|
||||
4
main.pas
4
main.pas
@ -3899,7 +3899,7 @@ try
|
||||
else s:=first(data.banReason, data.disconnectReason);
|
||||
addArray(md.table, ['%reason%', s]);
|
||||
|
||||
data.conn.reply.contentType:=ansistring(name2mimetype(sectionName, 'text/html'));
|
||||
data.conn.reply.contentType:=ansistring(name2mimetype(sectionName, 'text/html; charset=utf-8'));
|
||||
|
||||
md.cd:=data;
|
||||
md.tpl:=tpl2use;
|
||||
@ -5130,7 +5130,7 @@ var
|
||||
end;
|
||||
|
||||
if conn.reply.contentType = '' then
|
||||
conn.reply.contentType:=ansistring(if_(trim(getTill('<', s))='', 'text/html', 'text/plain'));
|
||||
conn.reply.contentType:=ansistring(if_(trim(getTill('<', s))='', 'text/html', 'text/plain'))+'; charset=utf-8';
|
||||
conn.reply.mode:=HRM_REPLY;
|
||||
conn.reply.bodyMode:=RBM_STRING;
|
||||
conn.reply.body:=UTF8encode(s);
|
||||
|
||||
@ -457,7 +457,8 @@ var
|
||||
vars: Tstrings;
|
||||
s: string;
|
||||
begin
|
||||
if not satisfied(md.cd) then exit;
|
||||
if not satisfied(md.cd) then
|
||||
exit;
|
||||
try
|
||||
result:=md.cd.conn.request.url;
|
||||
if pars.count < 2 then exit;
|
||||
@ -666,7 +667,7 @@ var
|
||||
procedure convert();
|
||||
begin
|
||||
if sameText(p, 'ansi') and sameText(par(1), 'utf-8') then
|
||||
result:=ansiToUTF8(ansistring(par(2)))
|
||||
result:=string(ansiToUTF8(ansistring(par(2))))
|
||||
else if sameText(p, 'utf-8') and sameText(par(1), 'ansi') then
|
||||
result:=utf8ToAnsi(ansistring(par(2)))
|
||||
end; // convert
|
||||
@ -1077,6 +1078,7 @@ var
|
||||
procedure load(fn:string; varname:string='');
|
||||
var
|
||||
from, size: int64;
|
||||
s: ansistring;
|
||||
begin
|
||||
result:='';
|
||||
from:=parI('from', 0);
|
||||
@ -1095,11 +1097,17 @@ var
|
||||
try result:=httpGet(fn, from, size)
|
||||
except result:='' end
|
||||
else
|
||||
result:=loadFile(uri2diskMaybe(fn), from, size);
|
||||
begin
|
||||
s:=loadFile(uri2diskMaybe(fn), from, size);
|
||||
result:=UTF8ToString(s);
|
||||
if result = '' then
|
||||
result:=s;
|
||||
end;
|
||||
|
||||
if varname = '' then
|
||||
begin
|
||||
if anyCharIn('/\',fn) then result:=macroQuote(result);
|
||||
if anyCharIn('/\',fn) then
|
||||
result:=macroQuote(result);
|
||||
exit;
|
||||
end;
|
||||
if ansiStartsStr(ENCODED_TABLE_HEADER, result) then
|
||||
@ -1962,7 +1970,7 @@ try
|
||||
result:=jsEncode(p, first(par(1),'''"'));
|
||||
|
||||
if name = 'base64' then
|
||||
result:=base64encode(UTF8encode(p));
|
||||
result:=string(base64encode(UTF8encode(p)));
|
||||
if name = 'base64decode' then
|
||||
result:=utf8ToString(base64decode(ansistring(p)));
|
||||
if name = 'md5' then
|
||||
|
||||
@ -1707,6 +1707,8 @@ with ThttpClient.createURL(url) do
|
||||
contentRangeEnd:=intToStr(from+size-1);
|
||||
get();
|
||||
result:=reply.dataString;
|
||||
if sameText('utf-8', reGet(ContentType, '; *charset=(.+) *($|;)')) then
|
||||
Result:=UTF8ToString(result);
|
||||
finally
|
||||
reply.free;
|
||||
Free;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user