From b49c15d043827c686bab185d654d95c819adf61e Mon Sep 17 00:00:00 2001 From: Massimo Melina Date: Fri, 8 May 2020 01:32:03 +0200 Subject: [PATCH] fix: unicode problems (removed optUTF8) --- main.pas | 15 +++++++-------- scriptLib.pas | 39 +++++++++++++++++++-------------------- utillib.pas | 8 -------- 3 files changed, 26 insertions(+), 36 deletions(-) diff --git a/main.pas b/main.pas index ae429dd..5ac46d9 100644 --- a/main.pas +++ b/main.pas @@ -3552,12 +3552,12 @@ try end; if otpl <> filelistTpl then - diffTpl.fullText:=optUTF8(diffTpl.over, folder.getRecursiveDiffTplAsStr()); + diffTpl.fullText:=folder.getRecursiveDiffTplAsStr(); isDMbrowser:= otpl = dmBrowserTpl; fullEncode:=FALSE; ofsRelUrl:=length(folder.url(fullEncode))+1; - ofsRelItemUrl:=length(optUTF8(diffTpl, folder.pathTill()))+1; + ofsRelItemUrl:=length(folder.pathTill())+1; // pathTill() is '/' for root, and 'just/folder', so we must accordingly consider a starting and trailing '/' for the latter case (bugfix by mars) if not folder.isRoot() then inc(ofsRelItemUrl, 2); @@ -3669,7 +3669,7 @@ else result:='-' end; // getETA function tplFromFile(f:Tfile):Ttpl; -begin result:=Ttpl.create(optUTF8(tpl, f.getRecursiveDiffTplAsStr()), tpl) end; +begin result:=Ttpl.create(f.getRecursiveDiffTplAsStr(), tpl) end; procedure setDefaultIP(v:string); var @@ -3743,7 +3743,7 @@ var begin if d.conn.reply.bodymode <> RBM_FILE then continue; t:=tpl2use['progress-download-file']; - fn:=optUTF8(tpl2use, d.lastFN); + fn:=d.lastFN; bytes:=d.conn.bytesSentLastItem; total:=d.conn.bytesPartial; end; @@ -3793,12 +3793,12 @@ var for i:=0 to length(data.uploadResults)-1 do with data.uploadResults[i] do files:=files+xtpl(tpl2use[ if_(reason='','upload-success','upload-failed') ],[ - '%item-name%', htmlEncode(macroQuote(optUTF8(tpl2use, fn))), + '%item-name%', htmlEncode(macroQuote(fn)), '%item-url%', macroQuote(encodeURL(fn)), '%item-size%', smartsize(size), '%item-resource%', f.resource+'\'+fn, '%idx%', intToStr(i+1), - '%reason%', optUTF8(tpl2use, reason), + '%reason%', reason, '%speed%', intToStr(speed div 1000), // legacy '%smart-speed%', smartsize(speed) ]); @@ -3840,7 +3840,7 @@ try addUploadResultsSymbols(); if data = NIL then s:='' else s:=first(data.banReason, data.disconnectReason); - addArray(md.table, ['%reason%', optUTF8(tpl2use, s)]); + addArray(md.table, ['%reason%', s]); data.conn.reply.contentType:=name2mimetype(sectionName, 'text/html'); if sectionName = 'ban' then data.conn.reply.mode:=HRM_DENY; @@ -4448,7 +4448,6 @@ function setTplText(text:string):boolean; begin result:=FALSE; // mod by mars //patch290(); -// if we'd use optUTF8() here, we couldn't make use of tpl.utf8, because text would not be parsed yet tpl.fullText:=text; tplIsCustomized:= text <> defaultTpl; if boolOnce(tplImport) then diff --git a/scriptLib.pas b/scriptLib.pas index 3024856..efda361 100644 --- a/scriptLib.pas +++ b/scriptLib.pas @@ -556,7 +556,7 @@ var s:=md.cd.urlvars.values[k]; if (s = '') and (md.cd.urlvars.indexOf(k) >= 0) then s:='1'; try - result:=noMacrosAllowed(optUTF8(md.tpl, s)); + result:=noMacrosAllowed(s); setVar(parEx('var'), result); // if no var is specified, it will break here, and result will have the value result:=''; except end; @@ -648,7 +648,7 @@ var if not satisfied(fld) then exit; e:=htmlEncode(encodeMarkers(fld.url(TRUE))); - d:=htmlEncode(encodeMarkers(optUTF8(md.tpl, fld.getFolder()+fld.name+'/'))); + d:=htmlEncode(encodeMarkers(fld.getFolder()+fld.name+'/')); ae:=split('/', e); ad:=split('/', d); p:=macroDequote(p); @@ -1598,11 +1598,11 @@ var else if name = '%style%' then result:=tpl['style'] else if name = '%timestamp%' then - result:=optUTF8(tpl, dateTimeToStr(now())) + result:=dateTimeToStr(now()) else if name = '%date%' then - result:=optUTF8(tpl, dateToStr(now())) + result:=dateToStr(now()) else if name = '%time%' then - result:=optUTF8(tpl, timeToStr(now())) + result:=timeToStr(now()) else if name = '%now%' then result:=floatToStr(now()) else if name = '%version%' then @@ -1610,7 +1610,7 @@ var else if name = '%build%' then result:=VERSION_BUILD else if name = '%uptime%' then - result:=optUTF8(tpl, uptimestr()) + result:=uptimestr() else if name = '%speed-out%' then result:=floatToStrF(srv.speedOut/1000, ffFixed, 7,2) else if name = '%speed-in%' then @@ -1654,7 +1654,7 @@ var else if name = '%url%' then result:=macroQuote(md.cd.conn.request.url) else if name = '%user%' then - result:=optUTF8(md.tpl, macroQuote(usr)) + result:=macroQuote(usr) else if name = '%password%' then result:=macroQuote(md.cd.conn.request.pwd) else if name = '%loggedin%' then @@ -1673,12 +1673,12 @@ var if assigned(md.folder) then if name = '%folder-item-comment%' then - result:=optUTF8(md.tpl, md.folder.getDynamicComment()) + result:=md.folder.getDynamicComment() else if name = '%folder-comment%' then begin result:=md.folder.getDynamicComment(); if result > '' then - result:=optUTF8(md.tpl, replaceText(tpl['folder-comment'], '%item-comment%', result)); + result:=replaceText(tpl['folder-comment'], '%item-comment%', result) end else if name = '%diskfree%' then result:=smartSize(diskSpaceAt(md.folder.resource)-minDiskSpace*MEGA) @@ -1689,11 +1689,11 @@ var else if name = '%parent-folder%' then result:=md.folder.parentURL() else if name = '%folder-name%' then - result:=optUTF8(md.tpl, md.folder.name) + result:=md.folder.name else if name = '%folder-resource%' then result:=md.folder.resource else if name = '%folder%' then - with md.folder do result:=optUTF8(md.tpl, if_(isRoot(), '/', getFolder()+name+'/')) + with md.folder do result:=if_(isRoot(), '/', getFolder()+name+'/') ; if assigned(md.f) then @@ -1702,7 +1702,7 @@ var s:=md.f.name; if md.hideExt and md.f.isFile() then setLength(s, length(s)-length(extractFileExt(s)) ); - result:=htmlEncode(macroQuote(optUTF8(md.tpl, s))) + result:=htmlEncode(macroQuote(s)) end else if name = '%item-type%' then if md.f.isLink() then @@ -1720,20 +1720,20 @@ var else if name = '%item-resource%' then result:=macroQuote(md.f.resource) else if name = '%item-ext%' then - result:=macroQuote(optUTF8(md.tpl, copy(extractFileExt(md.f.name), 2, MAXINT))) + result:=macroQuote(copy(extractFileExt(md.f.name), 2, MAXINT)) else if name = '%item-added-dt%' then result:=floatToStr(md.f.atime) else if name = '%item-modified-dt%' then result:=floatToStr(md.f.mtime) // these twos are actually redundant, {.time||when=%item-added-dt%.} else if name = '%item-added%' then - result:=optUTF8(md.tpl, datetimeToStr(md.f.atime)) + result:=datetimeToStr(md.f.atime) else if name = '%item-modified%' then - result:=if_(md.f.mtime=0, 'error', optUTF8(md.tpl, datetimeToStr(md.f.mtime))) + result:=if_(md.f.mtime=0, 'error', datetimeToStr(md.f.mtime)) else if name = '%item-comment%' then - result:=optUTF8(md.tpl, md.f.getDynamicComment(TRUE)) + result:=md.f.getDynamicComment(TRUE) else if name = '%item-url%' then - result:=macroQuote(optUTF8(md.tpl, md.f.url())) + result:=macroQuote(md.f.url()) ; if assigned(md.f) and assigned(md.tpl) then @@ -1883,7 +1883,6 @@ try r:=parF('when',now())+parF('offset',0); if s = 'y' then result:=floatToStr(r) else datetimeToString(result, first(s,'c'), r ); - result:=optUTF8(md.tpl, result); // we may have special chars from datetimeToString() end; if name = 'disconnect' then @@ -2052,9 +2051,9 @@ try else result:=p; - if name = 'maybe utf8' then + if name = 'maybe utf8' then // pre-unicode legacy if satisfied(md.tpl) then - result:=optUTF8(md.tpl.utf8, p); + result:=p; if name = 'after the list' then if md.afterTheList then diff --git a/utillib.pas b/utillib.pas index 046f06e..ffba5ba 100644 --- a/utillib.pas +++ b/utillib.pas @@ -215,8 +215,6 @@ function getTill(ss, s:string; included:boolean=FALSE):string; overload; function getTill(i:integer; s:string):string; overload; function singleLine(s:string):boolean; function poss(chars:TcharSet; s:string; ofs:integer=1):integer; -function optUTF8(bool:boolean; s:string):string; overload; -function optUTF8(tpl:Ttpl; s:string):string; overload; function optAnsi(bool:boolean; s:string):string; function utf8Test(s:string):boolean; function jsEncode(s, chars:string):string; @@ -2045,12 +2043,6 @@ setLength(result, 1000); setLength(result, getTempPath(length(result), @result[1])); end; // getTempDir -function optUTF8(bool:boolean; s:string):string; -begin if bool then result:=ansiToUtf8(s) else result:=s end; - -function optUTF8(tpl:Ttpl; s:string):string; inline; -begin result:=optUTF8(assigned(tpl) and tpl.utf8, s) end; - function optAnsi(bool:boolean; s:string):string; begin if bool then result:=UTF8toAnsi(s) else result:=s end;