Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not use shellescape on Windows + Remove Gemfile.lock #191

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ tmtags
coverage
rdoc
pkg
Gemfile.lock

## PROJECT::SPECIFIC
.bundle
Expand Down
40 changes: 0 additions & 40 deletions Gemfile.lock

This file was deleted.

7 changes: 6 additions & 1 deletion lib/pdfkit/pdfkit.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'rbconfig'
require 'shellwords'

class PDFKit
Expand Down Expand Up @@ -44,7 +45,11 @@ def command(path = nil)

args << (path || '-') # Write to file or stdout

args.shelljoin
if RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ # Windows
args.map{|str| str =~ /\s/ ? "\"#{str.gsub('"', '\"')}\"" : str}.join(' ')
else # Linux, OSX
args.shelljoin
end
end

def executable
Expand Down
30 changes: 24 additions & 6 deletions spec/pdfkit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,32 @@
pdfkit.command.should_not include('--disable-smart-shrinking')
end

it "should encapsulate string arguments in quotes" do
pdfkit = PDFKit.new('html', :header_center => "foo [page]")
pdfkit.command.should include "--header-center foo\\ \\[page\\]"
context "on Linux platform" do
before { stub_const("RbConfig::CONFIG", {'host_os' => 'linux'}) }

it "should encapsulate string arguments in quotes" do
pdfkit = PDFKit.new('html', :header_center => "foo [page]")
pdfkit.command.should include "--header-center foo\\ \\[page\\]"
end

it "should sanitize string arguments" do
pdfkit = PDFKit.new('html', :header_center => "$(ls)")
pdfkit.command.should include "--header-center \\$\\(ls\\)"
end
end

it "should sanitize string arguments" do
pdfkit = PDFKit.new('html', :header_center => "$(ls)")
pdfkit.command.should include "--header-center \\$\\(ls\\)"
context "on Windows platform" do
before { stub_const("RbConfig::CONFIG", {'host_os' => 'mingw'}) }

it "should encapsulate string arguments in quotes" do
pdfkit = PDFKit.new('html', :header_center => "foo [\"page\"]")
pdfkit.command.should include "--header-center \"foo [\\\"page\\\"]\""
end

it "should not sanitize string arguments" do
pdfkit = PDFKit.new('html', :header_center => "$(ls)")
pdfkit.command.should include "--header-center $(ls)"
end
end

it "read the source from stdin if it is html" do
Expand Down