Errors if file name contains escaped special characters (space, parenthesis etc)

Bug #500262 reported by narnie
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
chm2pdf (Ubuntu)
Confirmed
Undecided
Unassigned

Bug Description

Binary package hint: chm2pdf

I get the following error when trying to run the program. I have looked at packages.debian.org and found that the version they have there is the same under the unstable as we have in karmic so I couldn't install that deb.

 Here is the thrown error:

sh: Syntax error: "(" unexpected
sh: Syntax error: "(" unexpected
Traceback (most recent call last):
  File "/usr/bin/chm2pdf", line 1108, in <module>
    main(sys.argv)
  File "/usr/bin/chm2pdf", line 1102, in main
    convert_to_pdf(cfile, filename, outputfilename, options)
  File "/usr/bin/chm2pdf", line 318, in convert_to_pdf
    objective_urls=get_objective_urls_list(filename)
  File "/usr/bin/chm2pdf", line 116, in get_objective_urls_list
    flist=open(CHM2PDF_WORK_DIR+'/urlslist.txt','rU')
IOError: [Errno 2] No such file or directory: '/tmp/tmpcih9vQ/Python\\ In\\ A\\ Nutshell,\\ 2nd\\ Edition\\ (2006)/urlslist.txt'

With thanks,
Nathan

Tags: patch
Revision history for this message
Reto Knaak (reto-knaak) wrote :

Am I wrong or is your filename containing spaces?
I think this could be the cause of your problems.

Revision history for this message
Reto Knaak (reto-knaak) wrote :

Hi Narnie!

Your problem could be related to this other bug, for which I found a patch (working for my case).
Could you please check if this solves also your case?

https://bugs.launchpad.net/ubuntu/+source/chm2pdf/+bug/894193

If not, could you provide the CHM file causing the problem?

Kind regards!

Reto Knaak (reto-knaak)
Changed in chm2pdf (Ubuntu):
status: New → Confirmed
Revision history for this message
Reto Knaak (reto-knaak) wrote :

I searched and found the file "Python In A Nutshell, 2nd Edition (2006).chm" and tryied following:

- renaming the file so that it doesn't contains any special character like spaces or parenthesis, it converts well
- escaping the spaces in name of the file is not enough as also () need to be escaped (bash: syntax error near unexpected token '(' )
- escaping also ( and ) will give me exacly the situation reported by narnie.
- installing the patch of bug 894193 won't correct this

In the code, we have situatiuons like those:
        # the python interpreter handles files with spaces just fine, so we have to unescape
        # our spaces when passing files as arguments to library functions
        if os.path.exists(re.sub('\\\\ ', ' ', page_filename)) and (options['titlefile'] == '' or not options['titlefile'] in url):

And those will only catch escaped spaces, not other escaped special characters like ( or )

Reto Knaak (reto-knaak)
summary: - Errors when run
+ Errors if file name contains escaped special characters (space,
+ parenthesis etc)
Revision history for this message
Reto Knaak (reto-knaak) wrote :

I made this CHM file to test....
- contains spaces, ( and ) in the name of the file
- contains spaces, ( and ) also in the paths and names of htm pages

Revision history for this message
Reto Knaak (reto-knaak) wrote :

I tried to solve the problem, mostly using re.escape() instead using re.sub(' ', '\ ',
See the diff file for details....

Revision history for this message
Ubuntu Foundations Team Bug Bot (crichton) wrote :

The attachment "patch which will convert the previous chm file" of this bug report has been identified as being a patch. The ubuntu-reviewers team has been subscribed to the bug report so that they can review the patch. In the event that this is in fact not a patch you can resolve this situation by removing the tag 'patch' from the bug report and editing the attachment so that it is not flagged as a patch. Additionally, if you are member of the ubuntu-reviewers team please also unsubscribe the team from this bug report.

[This is an automated message performed by a Launchpad user owned by Brian Murray. Please contact him regarding any issues with the action taken in this bug report.]

tags: added: patch
Revision history for this message
prasad (prasadjoshi124) wrote :

Yet another way to solve the problem is quote ('') the filename.

Attaching the patch which fixes the problem.....

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.