rejetto forum

bad path error with %item-relative-folder%

Mars · 6 · 5737

0 Members and 1 Guest are viewing this topic.

Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2059
    • View Profile
rejetto code:
Quote
 procedure handleItem(f:Tfile);
   ....
  if recur then url:=copy(itemFolder, ofsRelUrl, MAXINT)
  else url:='';

  addArray(md.table, [
    '%item-folder%', itemFolder,

    '%item-relative-folder%', url
  ]);
The text in red is the cause of the bug, its value is determined for another use from a character string the length of which is superior to the necessary real value. The chaine of origin contains characters codified under the shape %xx, where from an overestimation of the variable

The following solution requires least resources and gives a correct result.

sometime the var %folder% is not defined for events then i introduce the var %item-base-folder% which give the same result

main.pas
Quote
function Tmainfrm.getFolderPage(folder:Tfile; conn:ThttpConn; otpl:Tobject):string;
var
...
  md: TmacroData;
  currentFolder:string; //add by mars

  procedure applySequential();
  .....
  procedure handleItem(f:Tfile);
    ...
  if recur then url:=copy(itemfolder, length(currentFolder)+1, MAXINT)      //mod by mars    else url:='';

  addArray(md.table, [
   '%item-folder%', macroquote(itemFolder),      //mod by mars
    '%item-base-folder%', macroquote(currentFolder),          //add by mars
    '%item-relative-folder%', macroquote(url)     //mod by mars

  ]);
...
      url:=s
      end
    else
      begin
      if recur then
        s:=copy(f.url(fullEncode), ofsRelUrl, MAXINT)+fingerprint
      else
        s:=f.relativeURL(fullEncode)+fingerprint;
      url:=baseurl+s;
      end;
  addArray(md.table, [
    '%item-url%', macroQuote(s),
    '%item-full-url%', macroQuote(url)
  ]);

  // select appropriate template
...
var
  i: integer;
begin
...
  ofsRelUrl:=length(folder.url(fullEncode))+1;  //create the error when full encode is true
...
  hasher:=Thasher.create();
  hasher.loadFrom(folder.resource);
  try
    if recur then currentFolder:=optUTF8(diffTpl, folder.getFolder()+if_(not folder.isRoot,folder.name+'/'));  //add by mars
    listing.fromFolder( folder, conn, recur );
    if not recur or (otpl <> filelistTpl) then
      listing.sort(conn, diffTpl['sort by']);
....
end; // getFolderPage

usage: http://127.0.0.1/......./?recursive

[folder=file=link]
<tr><td>
%item-name%
<p>%item-folder%
<p>%folder%
<p>%item-relative-folder%


« Last Edit: September 04, 2009, 11:33:08 PM by Mars »


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13510
    • View Profile
thank you mars,
but you are adding symbols in getFolderPage, where %folder% is defined for sure. They won't be visible in the events you say!
it should be fixed in next build.


Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2059
    • View Profile
always the same bug with your choice:

http://127.0.0.1/?recursive

with in the template

[file=folder=link]
  <tr><td>
  {.if|{.get|can delete.}{.and|{.get|can access.}|{.get|can archive item.}.}| <input type='checkbox' name='selection' value="%item-url%"> .}
  {.if|{.get|is new.}|<span class='flag'>&nbsp;NEW&nbsp;</span>.}
  {.if not|{.get|can access.}|<img src='/~img_lock'>.}
  <a href="%item-url%"><img src="%item-icon%"> %item-name%</a>
<p> folder= %folder%
<p> item-folder= %item-folder%
<p> item-relative= %item-relative-folder%
<p> item-name= %item-name%
<p> item-url = %item-url%
<p> item-full-url= %item-full-url%
<p> item-resource = %item-resource%


---------------------------
and compare the item-folder line with the relative line : first chars are deleted

using folder.getFolder()  is the best way

replace your line
  ofsRelItemUrl:=length(optUTF8(diffTpl, folder.pathTill()))+3;

by this one only
  ofsRelItemUrl:=length(optUTF8(diffTpl, folder.getFolder()))+1;


the time to evaluate ofsRelItemUrl is the same in each case ;)

« Last Edit: September 05, 2009, 09:13:19 PM by Mars »


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13510
    • View Profile
i made some tests and it was working to me.
can you tell me how to reproduce the bug?
give me the paths and urls to browse.


Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2059
    • View Profile
this line was not perfect with recursive from root
ofsRelItemUrl:=length(optUTF8(diffTpl, folder.pathTill()))+3;

update to

ofsRelItemUrl:=length(optUTF8(diffTpl, folder.pathTill()))+if_(not folder.isRoot,2)+1;

 ;)


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13510
    • View Profile
ok, to answer my question: the bug could be reproduced by doing a search from the root :)
thanks for the fix