[chm2pdf] Apply rebased Patch2: chm2pdf-0.9.1_space.patch from https://code.google.com/p/chm2pdf/issues/detail

Pavel Alexeev hubbitus at fedoraproject.org
Sat May 18 13:13:46 UTC 2013


commit d5fa376220b1582916be8beb3a9f4a4c78996920
Author: Pavel Alexeev (aka Pahan-Hubbitus) <pahan at hubbitus.info>
Date:   Sat May 18 17:13:26 2013 +0400

    Apply rebased Patch2: chm2pdf-0.9.1_space.patch from https://code.google.com/p/chm2pdf/issues/detail?id=3 to fix bz#869041
    Made additional Patch3: chm2pdf-0.9.1-shellquote.patch

 chm2pdf-0.9.1-shellquote.patch |   34 +++++++++++++++++++++++++++
 chm2pdf-0.9.1_space.patch      |   50 ++++++++++++++++++++++++++++++++++++++++
 chm2pdf.spec                   |   12 ++++++++-
 3 files changed, 95 insertions(+), 1 deletions(-)
---
diff --git a/chm2pdf-0.9.1-shellquote.patch b/chm2pdf-0.9.1-shellquote.patch
new file mode 100644
index 0000000..5c8c176
--- /dev/null
+++ b/chm2pdf-0.9.1-shellquote.patch
@@ -0,0 +1,34 @@
+--- chm2pdf.orig	2013-05-18 16:01:07.000000000 +0400
++++ chm2pdf	2013-05-18 15:57:24.000000000 +0400
+@@ -107,13 +107,17 @@
+     #print 'lister pages',lister.pages
+     return lister.pages
+ 
++''' http://stackoverflow.com/questions/35817/how-to-escape-os-system-calls-in-python '''
++def shellquote(s):
++    return "'" + s.replace("'", "'\\''") + "'"
++
+ def get_objective_urls_list(filename):
+     '''
+     takes the list of files inside the chm archive, with the correct urls of each one.
+     '''
+ 
+-    os.system('enum_chmLib '+filename+' > '+CHM2PDF_WORK_DIR+'/urlslist.txt')
+-    flist=open(CHM2PDF_WORK_DIR+'/urlslist.txt','rU')
++    os.system('enum_chmLib ' + shellquote(filename) + ' > ' + shellquote(CHM2PDF_WORK_DIR+'/urlslist.txt'))
++    flist=open(CHM2PDF_WORK_DIR + '/urlslist.txt','rU')
+     urls_list=[]
+     for line in flist.readlines()[3:]:
+         #print 'line',line
+@@ -1085,9 +1089,9 @@
+             print 'Will use the files in ' + CHM2PDF_ORIG_DIR + ' and ' + CHM2PDF_WORK_DIR + '.'
+     else:
+         if options['verbose'] == '--verbose' and options['verbositylevel'] == 'high':
+-            os.system('extract_chmLib ' + filename + ' ' + CHM2PDF_ORIG_DIR)
++            os.system('extract_chmLib ' + shellquote(filename) + ' ' + shellquote(CHM2PDF_ORIG_DIR))
+         else:
+-            os.system('extract_chmLib ' + filename + ' ' + CHM2PDF_ORIG_DIR + '&> /dev/null')
++            os.system('extract_chmLib ' + shellquote(filename) + ' ' + shellquote(CHM2PDF_ORIG_DIR) + '&> /dev/null')
+     
+     convert_to_pdf(cfile, filename, outputfilename, options)
+     shutil.rmtree(CHM2PDF_TEMP_WORK_DIR)
diff --git a/chm2pdf-0.9.1_space.patch b/chm2pdf-0.9.1_space.patch
new file mode 100644
index 0000000..28f4c93
--- /dev/null
+++ b/chm2pdf-0.9.1_space.patch
@@ -0,0 +1,50 @@
+--- chm2pdf.orig	2008-07-09 14:42:26.000000000 +0400
++++ chm2pdf	2013-05-18 16:16:48.097014228 +0400
+@@ -115,8 +115,14 @@
+     urls_list=[]
+     for line in flist.readlines()[3:]:
+         #print 'line',line
+-        spline=line.split()
+-        urls_list.append(spline[5])
++        #This won't work if internal paths of CHM contains spaces: e.g. /doc space/ will only become /doc
++        #spline=line.split()
++        #urls_list.append(spline[5])
++        #this should work better:
++        spline= re.sub(r".*?normal file\s*(.*?)\n$", "\\1", line)
++        if spline[0]=="/":
++          #print "got spline="+spline
++          urls_list.append( spline)
+     flist.close()
+     # os.remove(CHM2PDF_WORK_DIR+'/urlslist.txt')
+     
+@@ -148,13 +154,17 @@
+ 
+         img_filename = ''
+         for item in objective_urls:
+-            if iurl in item:
++            #objective_urls has "real path", whereas image_catcher.imgurls can contain %20!
++            #e.g. item='/doc space/image path/velocity space.gif  iurl=image%20path/velocity%20space.gif
++            iiurl= re.sub('%20',' ',iurl)
++            if iiurl in item:
+                 img_filename=CHM2PDF_ORIG_DIR+item
+                 if ';' in img_filename: #hack to get rid of mysterious ; in filenames and urls...
+                     img_filename=img_filename.split(';')[0]
+         # substitute the new image filenames - but only if an img_filename was found!
+         if img_filename:
+-            page=re.sub(iurl,img_filename,page)
++            #r = Python also has "raw strings" which do not apply special treatment to backslashes
++            page=re.sub(r'(?i)"'+iurl,'"'+re.sub('\\\\ ', ' ', img_filename),page)
+             
+ 
+     # We substitute the CSS URLs of input_file with the *actual* URLs on the CHM2PDF_ORIG_DIR directory
+@@ -459,6 +469,10 @@
+             page=pf.read()
+             pf.close()
+     
++            # Some names contain a '%20' (an HTML code for a space). We substitute with a "real space"
++            # otherwise we won't be able to match to the real files.
++            page = re.sub('%20',' ',page)
++
+             # Substitutions in 1st pass: we replace the original filenames with their corresponding "garbled" equivalents.
+             for match_string in  match_strings:
+                 replace_string = replace_garbled_strings[match_strings.index(match_string)]
diff --git a/chm2pdf.spec b/chm2pdf.spec
index fa17d90..97ca5a2 100644
--- a/chm2pdf.spec
+++ b/chm2pdf.spec
@@ -2,7 +2,7 @@
 
 Name:       chm2pdf
 Version:    0.9.1
-Release:    13%{?dist}
+Release:    14%{?dist}
 Summary:    A tool to convert CHM files to PDF files
 Group:      Applications/Publishing
 License:    GPLv2+
@@ -14,6 +14,10 @@ BuildRoot:  %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
 BuildRequires:  python-devel
 Requires:   python >= 2.5, python-chm, htmldoc
 Patch1:     chm2pdf_insecure_tempdirs.patch
+# https://code.google.com/p/chm2pdf/issues/detail?id=3
+Patch2:     chm2pdf-0.9.1_space.patch
+# Additional my patch for that bug
+Patch3:     chm2pdf-0.9.1-shellquote.patch
 
 %description
 A simple Python script that converts CHM files into PDF files.
@@ -21,6 +25,8 @@ A simple Python script that converts CHM files into PDF files.
 %prep
 %setup -q
 %patch1 -p1 -b .orig
+%patch2 -p0 -b .space
+%patch3 -p0 -b .shellquote
 
 %build
 CFLAGS="$RPM_OPT_FLAGS" %{__python} setup.py build
@@ -40,6 +46,10 @@ rm -rf $RPM_BUILD_ROOT
 
 
 %changelog
+* Sat May 18 2013 Pavel Alexeev <Pahan at Hubbitus.info> - 0.9.1-14
+- Apply rebased Patch2: chm2pdf-0.9.1_space.patch from https://code.google.com/p/chm2pdf/issues/detail?id=3 to fix bz#869041
+- Provide Patch3: chm2pdf-0.9.1-shellquote.patch
+
 * Wed Feb 13 2013 Fedora Release Engineering <rel-eng at lists.fedoraproject.org> - 0.9.1-13
 - Rebuilt for https://fedoraproject.org/wiki/Fedora_19_Mass_Rebuild
 


More information about the scm-commits mailing list