opendocument and filename with an apostrophe error lazarus / 31-LCL ---------------------------------------------------------------------- sng · 2013-10-12 21:22 Hi all I'm trying to use OpenDocument to open files on linux. Everything is ok as long as there is no apostrophe in the filename. For example Filename: /home/spiros/Just a 'Test'.txt I have a ShellListView with double-click handler: Code: [Select]OpenDocument(ShellListView1.Root+'/'+ShellListView1.Sele cted.Caption); When i try to open this file, i get: QuoteFailed to open "/home/spiros/Just a ''Test''.txt". Error when getting information for file '/home spiros/Just a ''Test''.txt': No such file or directory. Now I know about double apostrophe when within a string, but I think this shouldn't be happening here too... Is this a bug? Can i do anything to avoid this situation? Thanks Spiros ---------------------------------------------------------------------- typo · 2013-10-12 22:05 This should work: Code: [Select]OpenDocument('Just a ''Test''.txt'); ---------------------------------------------------------------------- sng · 2013-10-13 07:48 I have already tested hard-coding the file name and I 'm afraid it doesn't work... I still get the same error message as above. That's on 1.0.10 (debian) I have also tried it on windows (1.0.12) and it works!!! So I will download 1.0.12 for linux and will get back to you EDIT I have upgraded lazarus to 1.0.12 (on linux) but no joy... The problem is still there ---------------------------------------------------------------------- BigChimp · 2013-10-13 10:03 Definitely a bug IMO. ---------------------------------------------------------------------- sng · 2013-10-13 10:32 More on this issue There is a difference between windows and linux implementation of Opendocument. This is the code sysenvapis_win.inc Code: [Select][color=blue]// Open a document with the default application associated with it in the system[/color] function OpenDocument(APath: String): Boolean; begin   Result := OpenURL(APath); end; sysenvapis_unix.inc Code: [Select]// Open a document with the default application associated with it in the system function OpenDocument(APath: String): Boolean; var   lApp: string; begin   Result := True;   if not FileExistsUTF8(APath) then exit(false);   lApp:=FindFilenameOfCmd('xdg-open'); // Portland OSDL/FreeDesktop standard on Linux   if lApp='' then     lApp:=FindFilenameOfCmd('kfmclient'); // KDE command   if lApp='' then     lApp:=FindFilenameOfCmd('gnome-open'); // GNOME command   if lApp='' then     Exit(False);   if (APath<>'') and (APath[1]<>'"') then     APath:=QuotedStr(APath);   RunCmdFromPath(lApp,APath); end; So by the time we reach the line APath:=QuotedStr(APath);, the string is already quoted, and then it gets quoted again (so every '' becomes '''') - Please see my attachment So all I had to do was to replace  APath:=QuotedStr(APath); with  APath:='"'+APath+'"'; to get it to work. I don't know if it's the right way, but it seems to work in all cases So this is surely a bug. How do we report it? ---------------------------------------------------------------------- Bart · 2013-10-13 10:41 Open a ticket in the bugtracker, attaching a minimal testcase (sources, and include a testfile that causes problems) that shows the bug. Bart ---------------------------------------------------------------------- sng · 2013-10-13 11:19 Thanks Bart This is the bug report http://mantis.freepascal.org/view.php?id=25185 Spiros ---------------------------------------------------------------------- sng · 2013-11-01 14:27 Hi all This is an alternative OpenDocument for linux only If you would be kind enough to test it and report back. Iit would be nice to get reports for lightweight WMs (openbox, IceWM, etc.) The tarball contains a test project, some test documents and a README explaining things HOW TO CHECK Open each file under directory test-docs and check that they open in their default application Feel free to check on any other file To open a file   - double click on it (uses new OpenDocument)   - select it, right click and click     * Default OpenDocument (LCLIntf)     * New OpenDocument If something goes wrong (file does not open or opens with an app which is not the default), please open a terminal and execute Code: [Select]  cd opendoc   ./opdoc >[Desktop Environment]-on-[Distribution].log 2>&1 and send me this file (or post it here using pastebin or someting) You can see my log file named "xfce-debian-sid.log" (included in the archive)