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

Raise RuntimeException when try convert from unspported class #67

Closed atton closed 7 years ago

atton commented 7 years ago

I encountered this error message using RGhost.

[3] pry(main)> RGhost::Convert.new(nil).to :jpeg
NoMethodError: undefined method `empty?' for nil:NilClass
from /Users/atton/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/bundler/gems/rghost-141a28abb655/lib/rghost/ruby_ghost_engine.rb:156:in `shellescape'
[5] pry(main)> RGhost::Convert.new(true).to :jpeg
NoMethodError: undefined method `empty?' for nil:NilClass
from /Users/atton/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/bundler/gems/rghost-141a28abb655/lib/rghost/ruby_ghost_engine.rb:156:in `shellescape'

RGhost::Engine checks document class when render . However, this case statement not has else block. So If I try to convert irregular file, class validation is passed and go to crash the program.

I added else block which throw RuntimeError with rspec. and fix rspecs for my ruby version. I get results like it

2 deprecation warnings total                                                                    

Finished in 0.81987 seconds (files took 0.26971 seconds to load)                                
69 examples, 0 failures  
macOS Sierra 10.12.6 
$ ruby  -v
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin16]
$ rspec --version
RSpec 3.6
  - rspec-core 3.6.0
  - rspec-expectations 3.6.0
  - rspec-mocks 3.6.0
  - rspec-rails 3.6.1
  - rspec-support 3.6.0