pdfkit 0.4.6 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/pdfkit.rb CHANGED
@@ -1,5 +1,4 @@
1
- require 'rubygems'
2
1
  require 'pdfkit/source'
3
2
  require 'pdfkit/pdfkit'
4
3
  require 'pdfkit/middleware'
5
- require 'pdfkit/configuration'
4
+ require 'pdfkit/configuration'
data/pdfkit.gemspec CHANGED
@@ -1,85 +1,28 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
1
  # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "pdfkit/version"
5
4
 
6
5
  Gem::Specification.new do |s|
7
- s.name = %q{pdfkit}
8
- s.version = "0.4.6"
6
+ s.name = "pdfkit"
7
+ s.version = PDFKit::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Jared Pace", "Relevance"]
10
+ s.email = ["jared@codewordstudios.com"]
11
+ s.homepage = "http://github.com/jdpace/PDFKit"
12
+ s.summary = "HTML+CSS -> PDF"
13
+ s.description = "Uses wkhtmltopdf to create PDFs using HTML"
9
14
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["jdpace"]
12
- s.date = %q{2010-09-03}
13
- s.default_executable = %q{pdfkit}
14
- s.description = %q{Uses wkhtmltopdf to create PDFs using HTML}
15
- s.email = %q{jared@codewordstudios.com}
16
- s.executables = ["pdfkit"]
17
- s.extra_rdoc_files = [
18
- "LICENSE",
19
- "README.md"
20
- ]
21
- s.files = [
22
- ".document",
23
- ".gitignore",
24
- ".rspec",
25
- "Gemfile",
26
- "Gemfile.lock",
27
- "LICENSE",
28
- "POST_INSTALL",
29
- "README.md",
30
- "Rakefile",
31
- "VERSION",
32
- "bin/pdfkit",
33
- "lib/pdfkit.rb",
34
- "lib/pdfkit/configuration.rb",
35
- "lib/pdfkit/middleware.rb",
36
- "lib/pdfkit/pdfkit.rb",
37
- "lib/pdfkit/source.rb",
38
- "pdfkit.gemspec",
39
- "spec/fixtures/example.css",
40
- "spec/fixtures/example.html",
41
- "spec/middleware_spec.rb",
42
- "spec/pdfkit_spec.rb",
43
- "spec/source_spec.rb",
44
- "spec/spec_helper.rb"
45
- ]
46
- s.homepage = %q{http://github.com/jdpace/PDFKit}
47
- s.post_install_message = %q{******************************************************************
15
+ s.rubyforge_project = "pdfkit"
48
16
 
49
- Now install wkhtmltopdf binaries:
50
- Global: sudo `which pdfkit` --install-wkhtmltopdf
51
- or inside RVM folder: export TO=`which pdfkit | sed 's:/pdfkit:/wkhtmltopdf:'` && pdfkit --install-wkhtmltopdf
52
- (run pdfkit --help to see more options)
53
-
54
- ******************************************************************}
55
- s.rdoc_options = ["--charset=UTF-8"]
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
56
20
  s.require_paths = ["lib"]
57
- s.rubygems_version = %q{1.3.7}
58
- s.summary = %q{HTML+CSS -> PDF}
59
- s.test_files = [
60
- "spec/middleware_spec.rb",
61
- "spec/pdfkit_spec.rb",
62
- "spec/source_spec.rb",
63
- "spec/spec_helper.rb"
64
- ]
65
-
66
- if s.respond_to? :specification_version then
67
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
68
- s.specification_version = 3
69
21
 
70
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
71
- s.add_development_dependency(%q<rspec>, ["~> 2.0.0.beta.8"])
72
- s.add_development_dependency(%q<rspec-core>, ["~> 2.0.0.beta.8"])
73
- s.add_development_dependency(%q<mocha>, [">= 0"])
74
- else
75
- s.add_dependency(%q<rspec>, ["~> 2.0.0.beta.8"])
76
- s.add_dependency(%q<rspec-core>, ["~> 2.0.0.beta.8"])
77
- s.add_dependency(%q<mocha>, [">= 0"])
78
- end
79
- else
80
- s.add_dependency(%q<rspec>, ["~> 2.0.0.beta.8"])
81
- s.add_dependency(%q<rspec-core>, ["~> 2.0.0.beta.8"])
82
- s.add_dependency(%q<mocha>, [">= 0"])
83
- end
22
+ # Developmnet Dependencies
23
+ s.add_development_dependency(%q<rspec>, ["~> 2.2.0"])
24
+ s.add_development_dependency(%q<mocha>, [">= 0.9.10"])
25
+ s.add_development_dependency(%q<rack-test>, [">= 0.5.6"])
26
+ s.add_development_dependency(%q<activesupport>, [">= 3.0.8"])
84
27
  end
85
28
 
@@ -1,11 +1,136 @@
1
1
  require 'spec_helper'
2
2
 
3
+ def app; Rack::Lint.new(@app); end
4
+
5
+ def mock_app(options = {}, conditions = {})
6
+ main_app = lambda { |env|
7
+ @env = env
8
+ headers = {'Content-Type' => "text/html"}
9
+ [200, headers, @body || ['Hello world!']]
10
+ }
11
+
12
+ builder = Rack::Builder.new
13
+ builder.use PDFKit::Middleware, options, conditions
14
+ builder.run main_app
15
+ @app = builder.to_app
16
+ end
17
+
3
18
  describe PDFKit::Middleware do
19
+
20
+ describe "#call" do
21
+ describe "conditions" do
22
+ describe ":only" do
23
+
24
+ describe "regex" do
25
+ describe "one" do
26
+ before { mock_app({}, :only => %r[^/public]) }
27
+
28
+ context "matching" do
29
+ specify do
30
+ get 'http://www.example.org/public/test.pdf'
31
+ last_response.headers["Content-Type"].should == "application/pdf"
32
+ last_response.body.bytesize.should == PDFKit.new("Hello world!").to_pdf.bytesize
33
+ end
34
+ end
35
+
36
+ context "not matching" do
37
+ specify do
38
+ get 'http://www.example.org/secret/test.pdf'
39
+ last_response.headers["Content-Type"].should == "text/html"
40
+ last_response.body.should == "Hello world!"
41
+ end
42
+ end
43
+ end # one regex
44
+
45
+ describe "multiple" do
46
+ before { mock_app({}, :only => [%r[^/invoice], %r[^/public]]) }
47
+
48
+ context "matching" do
49
+ specify do
50
+ get 'http://www.example.org/public/test.pdf'
51
+ last_response.headers["Content-Type"].should == "application/pdf"
52
+ last_response.body.bytesize.should == PDFKit.new("Hello world!").to_pdf.bytesize
53
+ end
54
+ end
55
+
56
+ context "not matching" do
57
+ specify do
58
+ get 'http://www.example.org/secret/test.pdf'
59
+ last_response.headers["Content-Type"].should == "text/html"
60
+ last_response.body.should == "Hello world!"
61
+ end
62
+ end
63
+ end # multiple regex
64
+ end # regex
65
+
66
+ describe "string" do
67
+ describe "one" do
68
+ before { mock_app({}, :only => '/public') }
69
+
70
+ context "matching" do
71
+ specify do
72
+ get 'http://www.example.org/public/test.pdf'
73
+ last_response.headers["Content-Type"].should == "application/pdf"
74
+ last_response.body.bytesize.should == PDFKit.new("Hello world!").to_pdf.bytesize
75
+ end
76
+ end
77
+
78
+ context "not matching" do
79
+ specify do
80
+ get 'http://www.example.org/secret/test.pdf'
81
+ last_response.headers["Content-Type"].should == "text/html"
82
+ last_response.body.should == "Hello world!"
83
+ end
84
+ end
85
+ end # one string
86
+
87
+ describe "multiple" do
88
+ before { mock_app({}, :only => ['/invoice', '/public']) }
89
+
90
+ context "matching" do
91
+ specify do
92
+ get 'http://www.example.org/public/test.pdf'
93
+ last_response.headers["Content-Type"].should == "application/pdf"
94
+ last_response.body.bytesize.should == PDFKit.new("Hello world!").to_pdf.bytesize
95
+ end
96
+ end
97
+
98
+ context "not matching" do
99
+ specify do
100
+ get 'http://www.example.org/secret/test.pdf'
101
+ last_response.headers["Content-Type"].should == "text/html"
102
+ last_response.body.should == "Hello world!"
103
+ end
104
+ end
105
+ end # multiple string
106
+ end # string
107
+
108
+ end
109
+ end
110
+
111
+ describe "remove .pdf from PATH_INFO and REQUEST_URI" do
112
+ before { mock_app }
113
+
114
+ context "matching" do
115
+ specify do
116
+ get 'http://www.example.org/public/file.pdf'
117
+ @env["PATH_INFO"].should == "/public/file"
118
+ @env["REQUEST_URI"].should == "/public/file"
119
+ end
120
+ specify do
121
+ get 'http://www.example.org/public/file.txt'
122
+ @env["PATH_INFO"].should == "/public/file.txt"
123
+ @env["REQUEST_URI"].should be_nil
124
+ end
125
+ end
126
+
127
+ end
128
+ end
129
+
4
130
  describe "#translate_paths" do
5
-
6
131
  before do
7
132
  @pdf = PDFKit::Middleware.new({})
8
- @env = {'REQUEST_URI' => 'http://example.com/document.pdf', 'rack.url_scheme' => 'http', 'HTTP_HOST' => 'example.com'}
133
+ @env = { 'REQUEST_URI' => 'http://example.com/document.pdf', 'rack.url_scheme' => 'http', 'HTTP_HOST' => 'example.com' }
9
134
  end
10
135
 
11
136
  it "should correctly parse relative url with single quotes" do
@@ -27,23 +152,44 @@ describe PDFKit::Middleware do
27
152
  end
28
153
  end
29
154
 
30
- describe "#set_request_to_render_as_pdf" do
31
-
32
- before do
155
+ describe "#translate_paths with root_url configuration" do
156
+ before do
33
157
  @pdf = PDFKit::Middleware.new({})
158
+ @env = { 'REQUEST_URI' => 'http://example.com/document.pdf', 'rack.url_scheme' => 'http', 'HTTP_HOST' => 'example.com' }
159
+ PDFKit.configure do |config|
160
+ config.root_url = "http://example.net/"
161
+ end
162
+ end
34
163
 
35
- @pdf_env = {'PATH_INFO' => Pathname.new("file.pdf"), 'REQUEST_URI' => Pathname.new("file.pdf")}
36
- @non_pdf_env = {'PATH_INFO' => Pathname.new("file.txt"), 'REQUEST_URI' => Pathname.new("file.txt")}
164
+ it "should add the root_url" do
165
+ @body = %{<html><head><link href='/stylesheets/application.css' media='screen' rel='stylesheet' type='text/css' /></head><body><img alt='test' src="/test.png" /></body></html>}
166
+ body = @pdf.send :translate_paths, @body, @env
167
+ body.should == "<html><head><link href='http://example.net/stylesheets/application.css' media='screen' rel='stylesheet' type='text/css' /></head><body><img alt='test' src=\"http://example.net/test.png\" /></body></html>"
37
168
  end
38
169
 
39
- it "should replace .pdf in PATH_INFO when the extname is .pdf" do
40
- @pdf.send :set_request_to_render_as_pdf, @pdf_env
41
- @pdf_env['PATH_INFO'].should == "file"
170
+ after do
171
+ PDFKit.configure do |config|
172
+ config.root_url = nil
173
+ end
42
174
  end
43
-
44
- it "should replace .pdf in REQUEST_URI when the extname is .pdf" do
45
- @pdf.send :set_request_to_render_as_pdf, @pdf_env
46
- @pdf_env['REQUEST_URI'].should == "file"
47
- end
48
175
  end
176
+
177
+ it "should not get stuck rendering each request as pdf" do
178
+ mock_app
179
+ # false by default. No requests.
180
+ @app.send(:rendering_pdf?).should be_false
181
+
182
+ # Remain false on a normal request
183
+ get 'http://www.example.org/public/file'
184
+ @app.send(:rendering_pdf?).should be_false
185
+
186
+ # Return true on a pdf request.
187
+ get 'http://www.example.org/public/file.pdf'
188
+ @app.send(:rendering_pdf?).should be_true
189
+
190
+ # Restore to false on any non-pdf request.
191
+ get 'http://www.example.org/public/file'
192
+ @app.send(:rendering_pdf?).should be_false
193
+ end
194
+
49
195
  end
data/spec/pdfkit_spec.rb CHANGED
@@ -1,84 +1,95 @@
1
+ #encoding: UTF-8
1
2
  require 'spec_helper'
2
3
 
3
4
  describe PDFKit do
4
-
5
+
5
6
  context "initialization" do
6
7
  it "should accept HTML as the source" do
7
8
  pdfkit = PDFKit.new('<h1>Oh Hai</h1>')
8
9
  pdfkit.source.should be_html
9
10
  pdfkit.source.to_s.should == '<h1>Oh Hai</h1>'
10
11
  end
11
-
12
+
12
13
  it "should accept a URL as the source" do
13
14
  pdfkit = PDFKit.new('http://google.com')
14
15
  pdfkit.source.should be_url
15
16
  pdfkit.source.to_s.should == 'http://google.com'
16
17
  end
17
-
18
+
18
19
  it "should accept a File as the source" do
19
20
  file_path = File.join(SPEC_ROOT,'fixtures','example.html')
20
21
  pdfkit = PDFKit.new(File.new(file_path))
21
22
  pdfkit.source.should be_file
22
23
  pdfkit.source.to_s.should == file_path
23
24
  end
24
-
25
+
25
26
  it "should parse the options into a cmd line friedly format" do
26
27
  pdfkit = PDFKit.new('html', :page_size => 'Letter')
27
28
  pdfkit.options.should have_key('--page-size')
28
29
  end
29
-
30
+
30
31
  it "should provide default options" do
31
32
  pdfkit = PDFKit.new('<h1>Oh Hai</h1>')
32
- ['--disable-smart-shrinking', '--margin-top', '--margin-right', '--margin-bottom', '--margin-left'].each do |option|
33
+ ['--margin-top', '--margin-right', '--margin-bottom', '--margin-left'].each do |option|
33
34
  pdfkit.options.should have_key(option)
34
35
  end
35
36
  end
36
-
37
+
37
38
  it "should default to 'UTF-8' encoding" do
38
39
  pdfkit = PDFKit.new('Captación')
39
40
  pdfkit.options['--encoding'].should == 'UTF-8'
40
41
  end
41
-
42
+
42
43
  it "should not have any stylesheedt by default" do
43
44
  pdfkit = PDFKit.new('<h1>Oh Hai</h1>')
44
45
  pdfkit.stylesheets.should be_empty
45
46
  end
46
47
  end
47
-
48
+
48
49
  context "command" do
49
50
  it "should contstruct the correct command" do
50
51
  pdfkit = PDFKit.new('html', :page_size => 'Letter', :toc_l1_font_size => 12)
51
52
  pdfkit.command[0].should include('wkhtmltopdf')
52
- pdfkit.command[pdfkit.command.index('--page-size') + 1].should == 'Letter'
53
- pdfkit.command[pdfkit.command.index('--toc-l1-font-size') + 1].should == '12'
53
+ pdfkit.command[pdfkit.command.index('"--page-size"') + 1].should == '"Letter"'
54
+ pdfkit.command[pdfkit.command.index('"--toc-l1-font-size"') + 1].should == '"12"'
54
55
  end
55
-
56
+
56
57
  it "will not include default options it is told to omit" do
58
+ PDFKit.configure do |config|
59
+ config.default_options[:disable_smart_shrinking] = true
60
+ end
61
+
57
62
  pdfkit = PDFKit.new('html')
58
- pdfkit.command.should include('--disable-smart-shrinking')
63
+ pdfkit.command.should include('"--disable-smart-shrinking"')
59
64
  pdfkit = PDFKit.new('html', :disable_smart_shrinking => false)
60
- pdfkit.command.should_not include('--disable-smart-shrinking')
65
+ pdfkit.command.should_not include('"--disable-smart-shrinking"')
61
66
  end
62
-
67
+
63
68
  it "should encapsulate string arguments in quotes" do
64
69
  pdfkit = PDFKit.new('html', :header_center => "foo [page]")
65
- pdfkit.command[pdfkit.command.index('--header-center') + 1].should == 'foo [page]'
70
+ pdfkit.command[pdfkit.command.index('"--header-center"') + 1].should == '"foo [page]"'
66
71
  end
67
-
72
+
68
73
  it "read the source from stdin if it is html" do
69
74
  pdfkit = PDFKit.new('html')
70
- pdfkit.command[-2..-1].should == ['-', '-']
75
+ pdfkit.command[-2..-1].should == ['"-"', '"-"']
71
76
  end
72
-
77
+
73
78
  it "specify the URL to the source if it is a url" do
74
79
  pdfkit = PDFKit.new('http://google.com')
75
- pdfkit.command[-2..-1].should == ['http://google.com', '-']
80
+ pdfkit.command[-2..-1].should == ['"http://google.com"', '"-"']
76
81
  end
77
-
82
+
78
83
  it "should specify the path to the source if it is a file" do
79
84
  file_path = File.join(SPEC_ROOT,'fixtures','example.html')
80
85
  pdfkit = PDFKit.new(File.new(file_path))
81
- pdfkit.command[-2..-1].should == [file_path, '-']
86
+ pdfkit.command[-2..-1].should == [%Q{"#{file_path}"}, '"-"']
87
+ end
88
+
89
+ it "should specify the path for the ouput if a apth is given" do
90
+ file_path = "/path/to/output.pdf"
91
+ pdfkit = PDFKit.new("html")
92
+ pdfkit.command(file_path).last.should == %Q{"#{file_path}"}
82
93
  end
83
94
 
84
95
  it "should detect special pdfkit meta tags" do
@@ -91,30 +102,60 @@ describe PDFKit do
91
102
  </html>
92
103
  }
93
104
  pdfkit = PDFKit.new(body)
94
- pdfkit.command[pdfkit.command.index('--page-size') + 1].should == 'Legal'
95
- pdfkit.command[pdfkit.command.index('--orientation') + 1].should == 'Landscape'
105
+ pdfkit.command[pdfkit.command.index('"--page-size"') + 1].should == '"Legal"'
106
+ pdfkit.command[pdfkit.command.index('"--orientation"') + 1].should == '"Landscape"'
107
+ end
108
+
109
+ it "should detect special pdfkit meta tags despite bad markup" do
110
+ body = %{
111
+ <html>
112
+ <head>
113
+ <meta name="pdfkit-page_size" content="Legal"/>
114
+ <meta name="pdfkit-orientation" content="Landscape"/>
115
+ </head>
116
+ <br>
117
+ </html>
118
+ }
119
+ pdfkit = PDFKit.new(body)
120
+ pdfkit.command[pdfkit.command.index('"--page-size"') + 1].should == '"Legal"'
121
+ pdfkit.command[pdfkit.command.index('"--orientation"') + 1].should == '"Landscape"'
96
122
  end
123
+
124
+ it "should skip non-pdfkit meta tags" do
125
+ body = %{
126
+ <html>
127
+ <head>
128
+ <meta name="test-page_size" content="Legal"/>
129
+ <meta name="pdfkit-orientation" content="Landscape"/>
130
+ </head>
131
+ <br>
132
+ </html>
133
+ }
134
+ pdfkit = PDFKit.new(body)
135
+ pdfkit.command[pdfkit.command.index('"--orientation"') + 1].should == '"Landscape"'
136
+ end
137
+
97
138
  end
98
-
139
+
99
140
  context "#to_pdf" do
100
141
  it "should generate a PDF of the HTML" do
101
142
  pdfkit = PDFKit.new('html', :page_size => 'Letter')
102
143
  pdf = pdfkit.to_pdf
103
144
  pdf[0...4].should == "%PDF" # PDF Signature at beginning of file
104
145
  end
105
-
146
+
106
147
  it "should generate a PDF with a numerical parameter" do
107
148
  pdfkit = PDFKit.new('html', :header_spacing => 1)
108
149
  pdf = pdfkit.to_pdf
109
150
  pdf[0...4].should == "%PDF" # PDF Signature at beginning of file
110
151
  end
111
-
152
+
112
153
  it "should generate a PDF with a symbol parameter" do
113
154
  pdfkit = PDFKit.new('html', :page_size => :Letter)
114
155
  pdf = pdfkit.to_pdf
115
156
  pdf[0...4].should == "%PDF" # PDF Signature at beginning of file
116
157
  end
117
-
158
+
118
159
  it "should have the stylesheet added to the head if it has one" do
119
160
  pdfkit = PDFKit.new("<html><head></head><body>Hai!</body></html>")
120
161
  css = File.join(SPEC_ROOT,'fixtures','example.css')
@@ -122,7 +163,7 @@ describe PDFKit do
122
163
  pdfkit.to_pdf
123
164
  pdfkit.source.to_s.should include("<style>#{File.read(css)}</style>")
124
165
  end
125
-
166
+
126
167
  it "should prepend style tags if the HTML doesn't have a head tag" do
127
168
  pdfkit = PDFKit.new("<html><body>Hai!</body></html>")
128
169
  css = File.join(SPEC_ROOT,'fixtures','example.css')
@@ -130,49 +171,66 @@ describe PDFKit do
130
171
  pdfkit.to_pdf
131
172
  pdfkit.source.to_s.should include("<style>#{File.read(css)}</style><html>")
132
173
  end
133
-
174
+
134
175
  it "should throw an error if the source is not html and stylesheets have been added" do
135
176
  pdfkit = PDFKit.new('http://google.com')
136
177
  css = File.join(SPEC_ROOT,'fixtures','example.css')
137
178
  pdfkit.stylesheets << css
138
179
  lambda { pdfkit.to_pdf }.should raise_error(PDFKit::ImproperSourceError)
139
180
  end
181
+
182
+ it "should be able to deal with ActiveSupport::SafeBuffer" do
183
+ pdfkit = PDFKit.new(ActiveSupport::SafeBuffer.new "<html><head></head><body>Hai!</body></html>")
184
+ css = File.join(SPEC_ROOT,'fixtures','example.css')
185
+ pdfkit.stylesheets << css
186
+ pdfkit.to_pdf
187
+ pdfkit.source.to_s.should include("<style>#{File.read(css)}</style></head>")
188
+ end
189
+
140
190
  end
141
-
191
+
142
192
  context "#to_file" do
143
193
  before do
144
194
  @file_path = File.join(SPEC_ROOT,'fixtures','test.pdf')
145
195
  File.delete(@file_path) if File.exist?(@file_path)
146
196
  end
147
-
197
+
148
198
  after do
149
199
  File.delete(@file_path)
150
200
  end
151
-
201
+
152
202
  it "should create a file with the PDF as content" do
153
203
  pdfkit = PDFKit.new('html', :page_size => 'Letter')
154
- pdfkit.expects(:to_pdf).returns('PDF')
155
204
  file = pdfkit.to_file(@file_path)
156
205
  file.should be_instance_of(File)
157
- File.read(file.path).should == 'PDF'
206
+ File.read(file.path)[0...4].should == "%PDF" # PDF Signature at beginning of file
207
+ end
208
+
209
+ it "should not truncate data (in Ruby 1.8.6)" do
210
+ file_path = File.join(SPEC_ROOT,'fixtures','example.html')
211
+ pdfkit = PDFKit.new(File.new(file_path))
212
+ pdf_data = pdfkit.to_pdf
213
+ file = pdfkit.to_file(@file_path)
214
+ file_data = open(@file_path, 'rb') {|io| io.read }
215
+ pdf_data.size.should == file_data.size
158
216
  end
159
217
  end
160
-
218
+
161
219
  context "security" do
162
220
  before do
163
221
  @test_path = File.join(SPEC_ROOT,'fixtures','security-oops')
164
222
  File.delete(@test_path) if File.exist?(@test_path)
165
223
  end
166
-
224
+
167
225
  after do
168
226
  File.delete(@test_path) if File.exist?(@test_path)
169
227
  end
170
-
228
+
171
229
  it "should not allow shell injection in options" do
172
230
  pdfkit = PDFKit.new('html', :header_center => "a title\"; touch #{@test_path} #")
173
231
  pdfkit.to_pdf
174
232
  File.exist?(@test_path).should be_false
175
233
  end
176
234
  end
177
-
235
+
178
236
  end
data/spec/source_spec.rb CHANGED
@@ -17,6 +17,11 @@ describe PDFKit::Source do
17
17
  source = PDFKit::Source.new('<blink>Oh Hai!</blink>')
18
18
  source.should_not be_url
19
19
  end
20
+
21
+ it "should return false if passed HTML with embedded urls at the beginning of a line" do
22
+ source = PDFKit::Source.new("<blink>Oh Hai!</blink>\nhttp://www.google.com")
23
+ source.should_not be_url
24
+ end
20
25
  end
21
26
 
22
27
  describe "#file?" do
data/spec/spec_helper.rb CHANGED
@@ -6,13 +6,10 @@ require 'rspec'
6
6
  require 'rspec/autorun'
7
7
  require 'mocha'
8
8
  require 'rack'
9
+ require 'rack/test'
10
+ require 'active_support'
11
+ require 'custom_wkhtmltopdf_path' if File.exists?(File.join(SPEC_ROOT, 'custom_wkhtmltopdf_path.rb'))
9
12
 
10
13
  RSpec.configure do |config|
11
-
12
- config.before do
13
- PDFKit.any_instance.stubs(:wkhtmltopdf).returns(
14
- File.join(SPEC_ROOT,'..','bin','wkhtmltopdf-proxy')
15
- )
16
- end
17
-
14
+ include Rack::Test::Methods
18
15
  end