fix: unicode problems (file comments)

This commit is contained in:
Massimo Melina 2020-05-09 12:39:22 +02:00
parent 99af92cc18
commit edd0fada64
4 changed files with 16 additions and 30 deletions

View File

@ -145,14 +145,12 @@ type
last: record section:string; idx:integer; end; // cache for getIdx() last: record section:string; idx:integer; end; // cache for getIdx()
fileExts: TStringDynArray; fileExts: TStringDynArray;
strTable: THashedStringList; strTable: THashedStringList;
fUTF8: boolean;
fOver: Ttpl; fOver: Ttpl;
function getIdx(section:string):integer; function getIdx(section:string):integer;
function getTxt(section:string):string; function getTxt(section:string):string;
function newSection(section:string):PtplSection; function newSection(section:string):PtplSection;
procedure fromString(txt:string); procedure fromString(txt:string);
procedure setOver(v:Ttpl); procedure setOver(v:Ttpl);
procedure updateUTF8();
public public
onChange: TNotifyEvent; onChange: TNotifyEvent;
sections: array of TtplSection; sections: array of TtplSection;
@ -160,7 +158,6 @@ type
destructor Destroy; override; destructor Destroy; override;
property txt[section:string]:string read getTxt; default; property txt[section:string]:string read getTxt; default;
property fullText:string read src write fromString; property fullText:string read src write fromString;
property utf8:boolean read fUTF8;
property over:Ttpl read fOver write setOver; property over:Ttpl read fOver write setOver;
function sectionExist(section:string):boolean; function sectionExist(section:string):boolean;
function getTxtByExt(fileExt:string):string; function getTxtByExt(fileExt:string):string;
@ -1109,7 +1106,6 @@ first:=TRUE;
ptxt:=succ(ansiStrPos(bos, #10)); // get to the end of line (and then beyond) ptxt:=succ(ansiStrPos(bos, #10)); // get to the end of line (and then beyond)
first:=FALSE; first:=FALSE;
until ptxt = NIL; until ptxt = NIL;
updateUTF8();
if assigned(onChange) then if assigned(onChange) then
onChange(self); onChange(self);
end; // appendString end; // appendString
@ -1117,12 +1113,8 @@ end; // appendString
procedure Ttpl.setOver(v:Ttpl); procedure Ttpl.setOver(v:Ttpl);
begin begin
fOver:=v; fOver:=v;
updateUTF8();
end; // setOver end; // setOver
procedure Ttpl.updateUTF8();
begin fUTF8:=assigned(over) and over.utf8 or utf8test(fullText) end;
function Ttpl.getSections():TStringDynArray; function Ttpl.getSections():TStringDynArray;
var var
i: integer; i: integer;

View File

@ -494,7 +494,7 @@ z-index:1; /* without this .item-menu will be over*/ }
"speed":"%smart-speed%" "speed":"%smart-speed%"
}, },
{.if| {.length|%user%.} |{: {.if| {.length|%user%.} |{:
{.set item|{.force ansi|%folder%%item-name%.}|comment={.!uploaded by.} %user%.} {.set item|%folder%%item-name%|comment={.!uploaded by.} %user%.}
:}.} :}.}
[upload-failed] [upload-failed]
@ -534,7 +534,7 @@ z-index:1; /* without this .item-menu will be over*/ }
{.set|x|{.postvar|name.}.} {.set|x|{.postvar|name.}.}
{.break|if={.pos|\|var=x.}{.pos|/|var=x.}|result=forbidden.} {.break|if={.pos|\|var=x.}{.pos|/|var=x.}|result=forbidden.}
{.break|if={.not|{.can mkdir.}.}|result=not authorized.} {.break|if={.not|{.can mkdir.}.}|result=not authorized.}
{.set|x|{.force ansi|%folder%{.^x.}.}.} {.set|x|%folder%{.^x.}.}
{.break|if={.exists|{.^x.}.}|result=exists.} {.break|if={.exists|{.^x.}.}|result=exists.}
{.break|if={.not|{.length|{.mkdir|{.^x.}.}.}.}|result=failed.} {.break|if={.not|{.length|{.mkdir|{.^x.}.}.}.}|result=failed.}
{.add to log|{.!User.} %user% {.!created folder.} "{.^x.}".} {.add to log|{.!User.} %user% {.!created folder.} "{.^x.}".}
@ -545,9 +545,9 @@ z-index:1; /* without this .item-menu will be over*/ }
{.break|if={.not|{.can rename.}.}|result=forbidden.} {.break|if={.not|{.can rename.}.}|result=forbidden.}
{.break|if={.is file protected|{.postvar|from.}.}|result=forbidden.} {.break|if={.is file protected|{.postvar|from.}.}|result=forbidden.}
{.break|if={.is file protected|{.postvar|to.}.}|result=forbidden.} {.break|if={.is file protected|{.postvar|to.}.}|result=forbidden.}
{.set|x|{.force ansi|%folder%{.postvar|from.}.}.} {.set|x|%folder%{.postvar|from.}.}
{.set|yn|{.force ansi|{.postvar|to.}.}.} {.set|yn|{.postvar|to.}.}
{.set|y|{.force ansi|%folder%.}{.^yn.}.} {.set|y|%folder%{.^yn.}.}
{.break|if={.not|{.exists|{.^x.}.}.}|result=not found.} {.break|if={.not|{.exists|{.^x.}.}.}|result=not found.}
{.break|if={.exists|{.^y.}.}|result=exists.} {.break|if={.exists|{.^y.}.}|result=exists.}
{.set|comment| {.get item|{.^x.}|comment.} .} {.set|comment| {.get item|{.^x.}|comment.} .}
@ -561,12 +561,12 @@ z-index:1; /* without this .item-menu will be over*/ }
[ajax.move|no log] [ajax.move|no log]
{.check session.} {.check session.}
{.set|dst|{.force ansi|{.postvar|dst.}.}.} {.set|dst|{.postvar|dst.}.}
{.break|if={.not|{.and|{.can move.}|{.get|can delete.}|{.get|can upload|path={.^dst.}.}/and.}.} |result=forbidden.} {.break|if={.not|{.and|{.can move.}|{.get|can delete.}|{.get|can upload|path={.^dst.}.}/and.}.} |result=forbidden.}
{.set|log|{.!Moving items to.} {.^dst.}.} {.set|log|{.!Moving items to.} {.^dst.}.}
{.for each|fn|{.replace|:|{.no pipe||.}|{.force ansi|{.postvar|files.}.}.}|{: {.for each|fn|{.replace|:|{.no pipe||.}|{.postvar|files.}.}|{:
{.break|if={.is file protected|var=fn.}|result=forbidden.} {.break|if={.is file protected|var=fn.}|result=forbidden.}
{.set|x|{.force ansi|%folder%.}{.^fn.}.} {.set|x|%folder%{.^fn.}.}
{.set|y|{.^dst.}/{.^fn.}.} {.set|y|{.^dst.}/{.^fn.}.}
{.if not |{.exists|{.^x.}.}|{.^x.}: {.!not found.}|{: {.if not |{.exists|{.^x.}.}|{.^x.}: {.!not found.}|{:
{.if|{.exists|{.^y.}.}|{.^y.}: {.!already exists.}|{: {.if|{.exists|{.^y.}.}|{.^y.}: {.!already exists.}|{:
@ -578,7 +578,7 @@ z-index:1; /* without this .item-menu will be over*/ }
{.set item|{.^y.}|comment={.^comment.}.} {.set item|{.^y.}|comment={.^comment.}.}
:} | {: :} | {:
{.set|log|{.chr|13.}{.^fn.} (failed)|mode=append.} {.set|log|{.chr|13.}{.^fn.} (failed)|mode=append.}
{.maybe utf8|{.^fn.}.}: {.!not moved.} {.^fn.}: {.!not moved.}
:}/if.} :}/if.}
:}/if.} :}/if.}
:}.} :}.}
@ -591,14 +591,14 @@ z-index:1; /* without this .item-menu will be over*/ }
{.break|if={.not|{.can comment.}.} |result=forbidden.} {.break|if={.not|{.can comment.}.} |result=forbidden.}
{.for each|fn|{.replace|:|{.no pipe||.}|{.postvar|files.}.}|{: {.for each|fn|{.replace|:|{.no pipe||.}|{.postvar|files.}.}|{:
{.break|if={.is file protected|var=fn.}|result=forbidden.} {.break|if={.is file protected|var=fn.}|result=forbidden.}
{.set item|{.force ansi|%folder%{.^fn.}.}|comment={.force ansi|{.postvar|text.}.}.} {.set item|%folder%{.^fn.}|comment={.postvar|text.}.}
:}.} :}.}
{.pipe|ok.} {.pipe|ok.}
[ajax.changepwd|no log] [ajax.changepwd|no log]
{.check session.} {.check session.}
{.break|if={.not|{.can change pwd.}.} |result=forbidden.} {.break|if={.not|{.can change pwd.}.} |result=forbidden.}
{.if|{.length|{.set account||password={.force ansi|{.postvar|new.}.}.}/length.}|ok|failed.} {.if|{.length|{.set account||password={.postvar|new.}.}/length.}|ok|failed.}
[special:alias] [special:alias]
check session=if|{.{.cookie|HFS_SID_.} != {.postvar|token.}.}|{:{.cookie|HFS_SID_|value=|expires=-1.} {.break|result=bad session.}:} check session=if|{.{.cookie|HFS_SID_.} != {.postvar|token.}.}|{:{.cookie|HFS_SID_|value=|expires=-1.} {.break|result=bad session.}:}

View File

@ -1335,7 +1335,7 @@ function loadDescriptionFile(fn:string):string;
begin begin
result:=loadTextFile(fn); result:=loadTextFile(fn);
if result = '' then if result = '' then
result:=loadTextFile(fn+'\descript.ion'); result:=loadTextFile(fn+'\'+DESCRIPT_ION);
if (result > '') and mainfrm.oemForIonChk.checked then if (result > '') and mainfrm.oemForIonChk.checked then
OEMToCharBuff(@result[1], @result[1], length(result)); //to test OEMToCharBuff(@result[1], @result[1], length(result)); //to test
end; // loadDescriptionFile end; // loadDescriptionFile

View File

@ -215,8 +215,6 @@ function getTill(ss, s:string; included:boolean=FALSE):string; overload;
function getTill(i:integer; s:string):string; overload; function getTill(i:integer; s:string):string; overload;
function singleLine(s:string):boolean; function singleLine(s:string):boolean;
function poss(chars:TcharSet; s:string; ofs:integer=1):integer; function poss(chars:TcharSet; s:string; ofs:integer=1):integer;
function optAnsi(bool:boolean; s:string):string;
function utf8Test(s:string):boolean;
function jsEncode(s, chars:string):string; function jsEncode(s, chars:string):string;
function nonEmptyConcat(pre,s:string; post:string=''):string; function nonEmptyConcat(pre,s:string; post:string=''):string;
function first(a,b:integer):integer; overload; function first(a,b:integer):integer; overload;
@ -933,7 +931,9 @@ end;
function loadTextFile(fn:string):string; function loadTextFile(fn:string):string;
begin begin
try result:=IOUtils.TFile.ReadAllText(fn) try result:=IOUtils.TFile.ReadAllText(fn)
except result:='' end except result:='' end;
try result:=UTF8decode(result)
except end;
end; end;
function loadFile(fn:string; from:int64=0; size:int64=-1):ansistring; function loadFile(fn:string; from:int64=0; size:int64=-1):ansistring;
@ -2043,9 +2043,6 @@ setLength(result, 1000);
setLength(result, getTempPath(length(result), @result[1])); setLength(result, getTempPath(length(result), @result[1]));
end; // getTempDir end; // getTempDir
function optAnsi(bool:boolean; s:string):string;
begin if bool then result:=UTF8toAnsi(s) else result:=s end;
function blend(from,to_:Tcolor; perc:real):Tcolor; function blend(from,to_:Tcolor; perc:real):Tcolor;
var var
i: integer; i: integer;
@ -2083,9 +2080,6 @@ end; // jsEncode
function holdingKey(key:integer):boolean; function holdingKey(key:integer):boolean;
begin result:=getAsyncKeyState(key) and $8000 <> 0 end; begin result:=getAsyncKeyState(key) and $8000 <> 0 end;
function utf8Test(s:string):boolean;
begin result:=ansiContainsText(s, 'charset=UTF-8') end;
// concat pre+s+post only if s is non empty // concat pre+s+post only if s is non empty
function nonEmptyConcat(pre, s:string; post:string=''):string; function nonEmptyConcat(pre, s:string; post:string=''):string;
begin if s = '' then result:='' else result:=pre+s+post end; begin if s = '' then result:='' else result:=pre+s+post end;
@ -2414,7 +2408,7 @@ l:=length(s);
while i <= l do while i <= l do
begin begin
p:=posEx('&',s,i); p:=posEx('&',s,i);
t:=decodeURL(replaceStr(substr(s,i,if_(p=0,0,p-1)), '+',' '), FALSE); // TODO should we instead try to decode utf-8? doing so may affect calls to {.force ansi.} in the template t:=decodeURL(replaceStr(substr(s,i,if_(p=0,0,p-1)), '+',' ')); // TODO should we instead try to decode utf-8? doing so may affect calls to {.force ansi.} in the template
sl.add(t); sl.add(t);
if p = 0 then exit; if p = 0 then exit;
i:=p+1; i:=p+1;