rejetto forum

bug report to rejetto about VALIDFILENAME

Mars · 2 · 2808

0 Members and 1 Guest are viewing this topic.

Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2059
    • View Profile
Quote
procedure TmainFrm.filesBoxEdited(Sender:TObject; Node:TTreeNode; var S:String);
var
  f: Tfile;
begin
f:=node.data;
if f.name = s then exit;

if f.isFile() and not validFilename(s)
or (s = '')
or (pos('/',s) > 0)
then
  begin
  s:=node.text;
  msgDlg('Invalid filename', MB_ICONERROR);
  exit;
  end;

if existsNodeWithName(s, node.parent)
and (msgDlg(MSG_SAME_NAME, MB_ICONWARNING+MB_YESNO) <> IDYES) then
  begin
  s:=node.text;
  exit;
  end;

f.name:=s;
VFSmodified:=TRUE;
updateUrlBox();
end;

1) Is '(pos('/',s) > 0)' necessary? '/' is already an invalid character.

2)  An invalid filename is detected but only if it is a file. But under Windows, Files and Folders are considered as being a part of the same family, the test ' f.isfile' is too.


That incites me to subject a question to everyone:
Under Windows, it is possible to look for files in a some arborescence 'Find files or foders/ F3'.

you can user meta characters as * and ? . You can combinate a multi search by separate items by a ';'

*.pas;*.dcu;*.ini

In a folder,you can create 3 files with the name 'test;document.xxx' wher xxx is different every time ( txt , ini , log .
do a search on this folder with the exact name 'test;document.txt', there is no meta characters, However the result is not only one file named 'test;document.txt', but all files which contains 'test' or 'document.txt'.

Morality, it is necessary to banish also the character ';' in the name of files.
Quote
  ILLEGAL_FILE_CHARS = [#0..#31,'/','\',':','?','*','"','<','>','|',';'];[/quote]

If somebody wants that I give him a good reason, it is simple: HFS uses two caracters of separation (see in hfs.ini) and they are '|' and ';'

It maybe has no negative effects on the VFS but the caution is rigorous.
« Last Edit: February 23, 2009, 08:33:56 PM by mars »


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13510
    • View Profile
1. yes, it's necessary.
validFilename() is called only for files.
for other things that are not files, the "/" check is done.

but now i'm puzzling if it's ok to give such freedom for folders' name :-\

2. ah, yes, that's what i was on about.
point is: in the past i made this decision to limit the test to files only, because in the past only files were saved. Now also folders are saved thanks to folder archives.
Now i guess i should extend the test to the folders.


yes, you found a poor designed point of Windows: semicolon is used a special char for search, while it is a normal char for file names.
It can sometimes lead to problems, but that's not a reason for HFS to prevent the user from using a valid char in the names.
What if you add a file with ; in the VFS, and you click rename?
It will not let you accept the name until you remove the ";". Not acceptable.