Blob Blame History Raw
--- 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)