diff --git a/hslib.pas b/hslib.pas index c6b7ccc..1e65cfe 100644 --- a/hslib.pas +++ b/hslib.pas @@ -1366,7 +1366,7 @@ procedure ThttpConn.processInputBuffer(); 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 @@ procedure ThttpConn.processInputBuffer(); 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); diff --git a/main.pas b/main.pas index 9615a68..1f27601 100644 --- a/main.pas +++ b/main.pas @@ -3899,7 +3899,7 @@ procedure Tmainfrm.getPage(sectionName:string; data:TconnData; f:Tfile=NIL; tpl2 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 @@ procedure Tmainfrm.httpEvent(event:ThttpEvent; conn:ThttpConn); 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); diff --git a/scriptLib.pas b/scriptLib.pas index 9c5d392..25c50db 100644 --- a/scriptLib.pas +++ b/scriptLib.pas @@ -457,7 +457,8 @@ function cbMacros(fullMacro:string; pars:Tstrings; cbData:pointer):string; 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 @@ function cbMacros(fullMacro:string; pars:Tstrings; cbData:pointer):string; 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 @@ function cbMacros(fullMacro:string; pars:Tstrings; cbData:pointer):string; procedure load(fn:string; varname:string=''); var from, size: int64; + s: ansistring; begin result:=''; from:=parI('from', 0); @@ -1095,11 +1097,17 @@ function cbMacros(fullMacro:string; pars:Tstrings; cbData:pointer):string; 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 @@ function cbMacros(fullMacro:string; pars:Tstrings; cbData:pointer):string; 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 diff --git a/utillib.pas b/utillib.pas index 9ed17fa..23030bc 100644 --- a/utillib.pas +++ b/utillib.pas @@ -1707,6 +1707,8 @@ function httpGet(url:string; from:int64=0; size:int64=-1):string; contentRangeEnd:=intToStr(from+size-1); get(); result:=reply.dataString; + if sameText('utf-8', reGet(ContentType, '; *charset=(.+) *($|;)')) then + Result:=UTF8ToString(result); finally reply.free; Free;