Recent

Author Topic: opendocument and filename with an apostrophe error  (Read 5708 times)

sng

  • New member
  • *
  • Posts: 7
opendocument and filename with an apostrophe error
« on: October 12, 2013, 11:22:38 pm »
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.Selected.Caption);
When i try to open this file, i get:

Quote
Failed 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
« Last Edit: October 12, 2013, 11:28:00 pm by sng »

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: opendocument and filename with an apostrophe error
« Reply #1 on: October 13, 2013, 12:05:30 am »
This should work:

Code: [Select]
OpenDocument('Just a ''Test''.txt');

sng

  • New member
  • *
  • Posts: 7
Re: opendocument and filename with an apostrophe error
« Reply #2 on: October 13, 2013, 09:48:12 am »
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

« Last Edit: October 13, 2013, 10:19:24 am by sng »

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: opendocument and filename with an apostrophe error
« Reply #3 on: October 13, 2013, 12:03:33 pm »
Definitely a bug IMO.
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

sng

  • New member
  • *
  • Posts: 7
Re: opendocument and filename with an apostrophe error
« Reply #4 on: October 13, 2013, 12:32:36 pm »
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

  • Hero Member
  • *****
  • Posts: 5721
    • Bart en Mariska's Webstek
Re: opendocument and filename with an apostrophe error
« Reply #5 on: October 13, 2013, 12:41:31 pm »
Open a ticket in the bugtracker, attaching a minimal testcase (sources, and include a testfile that causes problems) that shows the bug.

Bart

sng

  • New member
  • *
  • Posts: 7
Re: opendocument and filename with an apostrophe error
« Reply #6 on: October 13, 2013, 01:19:42 pm »
Thanks Bart

This is the bug report
http://mantis.freepascal.org/view.php?id=25185

Spiros

sng

  • New member
  • *
  • Posts: 7
Re: opendocument and filename with an apostrophe error
« Reply #7 on: November 01, 2013, 03:27:46 pm »
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)

 

TinyPortal © 2005-2018