@@ -21,23 +21,25 @@ def initialize(source, target, soffice_command = nil, convert_to = nil)
21
21
determine_soffice_command
22
22
@source_type = check_source_type
23
23
24
+ # If the URL contains GET params, the '&' could break when being used
25
+ # as an argument to soffice. Wrap it in single quotes to escape it.
26
+ # Then strip them from the target temp file name
27
+ @escaped_source = @source_type == 1 ? @source : "'#{ @source } '"
28
+ @escaped_source_path = @source_type == 1 ? @source : URI . parse ( @source ) . path
29
+
24
30
unless @soffice_command && File . exists? ( @soffice_command )
25
31
raise IOError , "Can't find Libreoffice or Openoffice executable."
26
32
end
27
33
end
28
34
29
35
def convert
30
- orig_stdout = $stdout. clone
31
- $stdout. reopen File . new ( '/dev/null' , 'w' )
32
36
Dir . mktmpdir { |target_path |
33
- # If the URL contains GET params, the '&' could break when being used
34
- # as an argument to soffice. Wrap it in single quotes to escape it.
35
- escaped_source = @source_type == 1 ? @source : "'#{ @source } '"
36
- pid = Spoon . spawnp ( @soffice_command , "--headless" , "--convert-to" , @convert_to , source , "--outdir" , target_path )
37
+ orig_stdout = $stdout. clone
38
+ $stdout. reopen File . new ( '/dev/null' , 'w' )
39
+ pid = Spoon . spawnp ( @soffice_command , "--headless" , "--convert-to" , @convert_to , @escaped_source , "--outdir" , target_path )
37
40
Process . waitpid ( pid )
38
41
$stdout. reopen orig_stdout
39
- escaped_source_path = @source_type == 1 ? @source : URI . parse ( @source ) . path # Strip any GET params that the URL may have
40
- target_tmp_file = "#{ target_path } /#{ File . basename ( escaped_source_path , ".*" ) } .#{ File . basename ( @convert_to , ":*" ) } "
42
+ target_tmp_file = "#{ target_path } /#{ File . basename ( @escaped_source_path , ".*" ) } .#{ File . basename ( @convert_to , ":*" ) } "
41
43
FileUtils . cp target_tmp_file , @target
42
44
}
43
45
end
0 commit comments