rghost icon indicating copy to clipboard operation
rghost copied to clipboard

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

Open pudiva opened this issue 12 years ago • 1 comments

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.

pudiva avatar Oct 03 '13 23:10 pudiva

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])

cdokolas avatar Jun 23 '23 11:06 cdokolas