shairontoledo / rghost

RGhost is a document creation and conversion API. It uses the Ghostscript framework for the format conversion, utilizes EPS templates and is optimized to work with larger documents. Support(PDF,PS,GIF,TIF,PNG,JPG,etc)
http://rghost.rubyforge.org
MIT License
187 stars 46 forks source link

Fail when `RGhost::Config::GS[:path]` has spaces #44

Open pudiva opened 11 years ago

pudiva commented 11 years ago

Setup

Windows 7 --- Microsoft Windows [versão 6.1.7601] Ghostscript GPL 9.10 --- GPL Ghostscript 9.10 (2013-08-30) Ruby 1.9.3 --- ruby 1.9.3p448 (2013-06-27) [i386-mingw32]

How to reproduce

Run teh test program in teh docs with RGhost::Config::GS[:path] set to anything containing spaces. For example:

require 'rubygems'
require 'rghost'
RGhost::Config::GS[:path]= 'C:\\Program Files (x86)\\gs\\gs9.10\\bin\\gswin32c.exe'
RGhost::Config.is_ok?.render :pdf, :filename => "mytest.pdf"

which gave me

C:\Users\IGOrrr\Desktop\pdfruby>ruby pdfruby.rb
C:/programs/ruby/ruby-1.9.3-p448-i386-mingw32/lib/ruby/gems/1.9.1/gems/rghost-0.
9.3/lib/rghost/ruby_ghost_engine.rb:86:in `render': RGhost::RenderException
        from C:/programs/ruby/ruby-1.9.3-p448-i386-mingw32/lib/ruby/gems/1.9.1/g
ems/rghost-0.9.3/lib/rghost/document.rb:238:in `render'
        from pdfruby.rb:4:in `<main>'

Source of problem

I tracked teh problem down to gs_alone.rb:15

r=system(RGhost::Config::GS[:path]+cmd)

It will work, if you put quotes around, like this:

r=system('"'+RGhost::Config::GS[:path]+'"'+cmd)

But not if you put teh quotes inside teh string, like this:

RGhost::Config::GS[:path]= '"C:\\Program Files (x86)\\gs\\gs9.10\\bin\\gswin32c.exe"'

because this path can't be found by gs_alone.rb:12

unless File.exists?(RGhost::Config::GS[:path].to_s)

Conclusion

It will probably break on linuxes and macs too. Must escape teh path, or warn users.

cdokolas commented 1 year ago

Had this problem myself when using via asciidoctor-pdf on Windows 11. I had to re-install ghostscript to a path that had no spaces and I set the GS environment variable like this:

set GS=C:\\Dev\\Tools\\gs\\gs10.01.2\\bin\\gswin64c.exe

(asciidoctor-pdf copies this environment variable to RGhost::Config::GS[:path])