pdfkit 0.8.2 → 0.8.7.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of pdfkit might be problematic. Click here for more details.

data/spec/pdfkit_spec.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  #encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
2
4
  require 'spec_helper'
3
5
 
4
6
  describe PDFKit do
@@ -23,6 +25,13 @@ describe PDFKit do
23
25
  expect(pdfkit.source.to_s).to eq(file_path)
24
26
  end
25
27
 
28
+ it "accepts a Tempfile as the source" do
29
+ file_path = File.join(SPEC_ROOT,'fixtures','example.html')
30
+ pdfkit = PDFKit.new(Tempfile.new(file_path))
31
+ expect(pdfkit.source).to be_file
32
+ expect(pdfkit.source.to_s).to match(/^#{Dir.tmpdir}/)
33
+ end
34
+
26
35
  # Options
27
36
  ## options keys
28
37
  it "drops options without values" do
@@ -232,12 +241,12 @@ describe PDFKit do
232
241
 
233
242
  it "read the source from stdin if it is html" do
234
243
  pdfkit = PDFKit.new('html')
235
- expect(pdfkit.command).to match /- -$/
244
+ expect(pdfkit.command).to match(/- -$/)
236
245
  end
237
246
 
238
247
  it "specifies the URL to the source if it is a url" do
239
248
  pdfkit = PDFKit.new('http://google.com')
240
- expect(pdfkit.command).to match /"http:\/\/google.com" -$/
249
+ expect(pdfkit.command).to match(/"http:\/\/google.com" -$/)
241
250
  end
242
251
 
243
252
  it "does not break Windows paths" do
@@ -249,13 +258,19 @@ describe PDFKit do
249
258
  it "specifies the path to the source if it is a file" do
250
259
  file_path = File.join(SPEC_ROOT,'fixtures','example.html')
251
260
  pdfkit = PDFKit.new(File.new(file_path))
252
- expect(pdfkit.command).to match /#{file_path} -$/
261
+ expect(pdfkit.command).to match(/#{file_path} -$/)
262
+ end
263
+
264
+ it "specifies the path to the source if it is a tempfile" do
265
+ file_path = File.join(SPEC_ROOT,'fixtures','example.html')
266
+ pdfkit = PDFKit.new(Tempfile.new(file_path))
267
+ expect(pdfkit.command).to match(/#{Dir.tmpdir}\S+ -$/)
253
268
  end
254
269
 
255
270
  it "specifies the path for the ouput if a path is given" do
256
271
  file_path = "/path/to/output.pdf"
257
272
  pdfkit = PDFKit.new("html")
258
- expect(pdfkit.command(file_path)).to match /#{file_path}$/
273
+ expect(pdfkit.command(file_path)).to match(/#{file_path}$/)
259
274
  end
260
275
 
261
276
  it "detects special pdfkit meta tags" do
@@ -384,9 +399,27 @@ describe PDFKit do
384
399
  end
385
400
  end
386
401
 
402
+ it "does not use xvfb-run wrapper by default" do
403
+ pdfkit = PDFKit.new('html')
404
+ expect(pdfkit.command).not_to include 'xvfb-run'
405
+ end
406
+
407
+ it "uses xvfb-run wrapper when option of using xvfb is configured" do
408
+ PDFKit.configure do |config|
409
+ config.use_xvfb = true
410
+ end
411
+
412
+ pdfkit = PDFKit.new('html')
413
+ expect(pdfkit.command).to include 'xvfb-run'
414
+
415
+ PDFKit.configure do |config|
416
+ config.use_xvfb = false
417
+ end
418
+ end
419
+
387
420
  context "on windows" do
388
421
  before do
389
- allow_any_instance_of(PDFKit).to receive(:host_is_windows?).and_return(true)
422
+ allow(PDFKit::OS).to receive(:host_is_windows?).and_return(true)
390
423
  end
391
424
 
392
425
  it "escapes special windows characters" do
@@ -470,6 +503,14 @@ describe PDFKit do
470
503
  expect(pdfkit.source.to_s).to include("<style>#{File.read(css)}</style></head>")
471
504
  end
472
505
 
506
+ it "can deal with ActiveSupport::SafeBuffer if the HTML doesn't have a head tag" do
507
+ pdfkit = PDFKit.new(ActiveSupport::SafeBuffer.new "<html><body>Hai!</body></html>")
508
+ css = File.join(SPEC_ROOT,'fixtures','example.css')
509
+ pdfkit.stylesheets << css
510
+ pdfkit.to_pdf
511
+ expect(pdfkit.source.to_s).to include("<style>#{File.read(css)}</style>")
512
+ end
513
+
473
514
  it "escapes \\X in stylesheets" do
474
515
  pdfkit = PDFKit.new("<html><head></head><body>Hai!</body></html>")
475
516
  css = File.join(SPEC_ROOT,'fixtures','example_with_hex_symbol.css')
@@ -481,7 +522,7 @@ describe PDFKit do
481
522
  #NOTICE: This test is failed if use wkhtmltopdf-binary (0.9.9.1)
482
523
  it "throws an error if it is unable to connect" do
483
524
  pdfkit = PDFKit.new("http://google.com/this-should-not-be-found/404.html")
484
- expect { pdfkit.to_pdf }.to raise_error /exitstatus=1/
525
+ expect { pdfkit.to_pdf }.to raise_error PDFKit::ImproperWkhtmltopdfExitStatus, /exitstatus=1/
485
526
  end
486
527
 
487
528
  it "does not throw an error if it is unable to connect", pending: 'this test works for wkhtmltopdf-binary (0.9.9.1)' do
data/spec/source_spec.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe PDFKit::Source do
@@ -12,6 +14,11 @@ describe PDFKit::Source do
12
14
  expect(source).not_to be_url
13
15
  end
14
16
 
17
+ it "returns false if passed a tempfile" do
18
+ source = PDFKit::Source.new(::Tempfile.new(__FILE__))
19
+ expect(source).not_to be_url
20
+ end
21
+
15
22
  it "returns false if passed HTML" do
16
23
  source = PDFKit::Source.new('<blink>Oh Hai!</blink>')
17
24
  expect(source).not_to be_url
@@ -29,6 +36,11 @@ describe PDFKit::Source do
29
36
  expect(source).to be_file
30
37
  end
31
38
 
39
+ it "returns true if passed a tempfile" do
40
+ source = PDFKit::Source.new(::Tempfile.new(__FILE__))
41
+ expect(source).to be_file
42
+ end
43
+
32
44
  it "returns false if passed a url like string" do
33
45
  source = PDFKit::Source.new('http://google.com')
34
46
  expect(source).not_to be_file
@@ -51,6 +63,11 @@ describe PDFKit::Source do
51
63
  expect(source).not_to be_html
52
64
  end
53
65
 
66
+ it "returns false if passed a tempfile" do
67
+ source = PDFKit::Source.new(::Tempfile.new(__FILE__))
68
+ expect(source).not_to be_html
69
+ end
70
+
54
71
  it "returns false if passed a url like string" do
55
72
  source = PDFKit::Source.new('http://google.com')
56
73
  expect(source).not_to be_html
@@ -63,6 +80,11 @@ describe PDFKit::Source do
63
80
  expect(source.to_input_for_command).to eq "\"https://www.google.com/search?q='cat%3Cdev/zero%3E/dev/null'\""
64
81
  end
65
82
 
83
+ it "URI escapes source URI only escape part of it" do
84
+ source = PDFKit::Source.new("https://www.google.com/search?q='%20 sleep 5'")
85
+ expect(source.to_input_for_command).to eq "\"https://www.google.com/search?q='%2520%20sleep%205'\""
86
+ end
87
+
66
88
  it "does not URI escape previously escaped source URLs" do
67
89
  source = PDFKit::Source.new("https://www.google.com/search?q='cat%3Cdev/zero%3E/dev/null'")
68
90
  expect(source.to_input_for_command).to eq "\"https://www.google.com/search?q='cat%3Cdev/zero%3E/dev/null'\""
@@ -77,6 +99,11 @@ describe PDFKit::Source do
77
99
  source = PDFKit::Source.new(::File.new(__FILE__))
78
100
  expect(source.to_input_for_command).to match 'spec/source_spec.rb'
79
101
  end
102
+
103
+ it "returns the file path for tempfile sources" do
104
+ source = PDFKit::Source.new(file = ::Tempfile.new(__FILE__))
105
+ expect(source.to_input_for_command).to match file.path
106
+ end
80
107
  end
81
108
 
82
109
  describe "#to_s" do
@@ -90,6 +117,11 @@ describe PDFKit::Source do
90
117
  expect(source.to_s).to eq(__FILE__)
91
118
  end
92
119
 
120
+ it "returns a path if passed a tempfile" do
121
+ source = PDFKit::Source.new(file = ::Tempfile.new(__FILE__))
122
+ expect(source.to_s).to eq(file.path)
123
+ end
124
+
93
125
  it "returns the url if passed a url like string" do
94
126
  source = PDFKit::Source.new('http://google.com')
95
127
  expect(source.to_s).to eq('http://google.com')
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  SPEC_ROOT = File.dirname(__FILE__)
2
4
  $LOAD_PATH.unshift(SPEC_ROOT)
3
5
  $LOAD_PATH.unshift(File.join(SPEC_ROOT, '..', 'lib'))
@@ -6,13 +8,15 @@ SimpleCov.start do
6
8
  add_filter 'spec/'
7
9
  end
8
10
 
11
+ Warning[:deprecated] = true if defined?(Warning.[]=)
12
+
9
13
  require 'pdfkit'
10
14
  require 'rspec'
11
15
  require 'mocha'
12
16
  require 'rack'
13
17
  require 'rack/test'
14
18
  require 'active_support'
15
- require 'custom_wkhtmltopdf_path' if File.exists?(File.join(SPEC_ROOT, 'custom_wkhtmltopdf_path.rb'))
19
+ require 'custom_wkhtmltopdf_path' if File.exist?(File.join(SPEC_ROOT, 'custom_wkhtmltopdf_path.rb'))
16
20
 
17
21
  RSpec.configure do |config|
18
22
  include Rack::Test::Methods
metadata CHANGED
@@ -1,112 +1,98 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pdfkit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.2
4
+ version: 0.8.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jared Pace
8
8
  - Relevance
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-08-26 00:00:00.000000000 Z
12
+ date: 2022-10-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - '>='
18
+ - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: 3.0.8
20
+ version: 4.1.11
21
21
  type: :development
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - '>='
25
+ - - ">="
26
26
  - !ruby/object:Gem::Version
27
- version: 3.0.8
27
+ version: 4.1.11
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: mocha
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - '>='
32
+ - - ">="
33
33
  - !ruby/object:Gem::Version
34
34
  version: 0.9.10
35
35
  type: :development
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - '>='
39
+ - - ">="
40
40
  - !ruby/object:Gem::Version
41
41
  version: 0.9.10
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: rack-test
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - '>='
46
+ - - ">="
47
47
  - !ruby/object:Gem::Version
48
48
  version: 0.5.6
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - '>='
53
+ - - ">="
54
54
  - !ruby/object:Gem::Version
55
55
  version: 0.5.6
56
- - !ruby/object:Gem::Dependency
57
- name: i18n
58
- requirement: !ruby/object:Gem::Requirement
59
- requirements:
60
- - - ~>
61
- - !ruby/object:Gem::Version
62
- version: 0.6.11
63
- type: :development
64
- prerelease: false
65
- version_requirements: !ruby/object:Gem::Requirement
66
- requirements:
67
- - - ~>
68
- - !ruby/object:Gem::Version
69
- version: 0.6.11
70
56
  - !ruby/object:Gem::Dependency
71
57
  name: rake
72
58
  requirement: !ruby/object:Gem::Requirement
73
59
  requirements:
74
- - - ~>
60
+ - - ">="
75
61
  - !ruby/object:Gem::Version
76
- version: 0.9.2
62
+ version: 12.3.3
77
63
  type: :development
78
64
  prerelease: false
79
65
  version_requirements: !ruby/object:Gem::Requirement
80
66
  requirements:
81
- - - ~>
67
+ - - ">="
82
68
  - !ruby/object:Gem::Version
83
- version: 0.9.2
69
+ version: 12.3.3
84
70
  - !ruby/object:Gem::Dependency
85
71
  name: rdoc
86
72
  requirement: !ruby/object:Gem::Requirement
87
73
  requirements:
88
- - - ~>
74
+ - - ">="
89
75
  - !ruby/object:Gem::Version
90
76
  version: 4.0.1
91
77
  type: :development
92
78
  prerelease: false
93
79
  version_requirements: !ruby/object:Gem::Requirement
94
80
  requirements:
95
- - - ~>
81
+ - - ">="
96
82
  - !ruby/object:Gem::Version
97
83
  version: 4.0.1
98
84
  - !ruby/object:Gem::Dependency
99
85
  name: rspec
100
86
  requirement: !ruby/object:Gem::Requirement
101
87
  requirements:
102
- - - ~>
88
+ - - "~>"
103
89
  - !ruby/object:Gem::Version
104
90
  version: '3.0'
105
91
  type: :development
106
92
  prerelease: false
107
93
  version_requirements: !ruby/object:Gem::Requirement
108
94
  requirements:
109
- - - ~>
95
+ - - "~>"
110
96
  - !ruby/object:Gem::Version
111
97
  version: '3.0'
112
98
  description: Uses wkhtmltopdf to create PDFs using HTML
@@ -116,12 +102,15 @@ executables: []
116
102
  extensions: []
117
103
  extra_rdoc_files: []
118
104
  files:
119
- - .document
120
- - .gitignore
121
- - .rspec
122
- - .ruby-gemset
123
- - .ruby-version
124
- - .travis.yml
105
+ - ".document"
106
+ - ".github/workflows/release-drafter.yml"
107
+ - ".github/workflows/stale.yml"
108
+ - ".github/workflows/test.yml"
109
+ - ".gitignore"
110
+ - ".rspec"
111
+ - ".ruby-gemset"
112
+ - ".ruby-version"
113
+ - ".travis.yml"
125
114
  - CHANGELOG.md
126
115
  - Gemfile
127
116
  - LICENSE
@@ -130,40 +119,46 @@ files:
130
119
  - Rakefile
131
120
  - lib/pdfkit.rb
132
121
  - lib/pdfkit/configuration.rb
122
+ - lib/pdfkit/html_preprocessor.rb
133
123
  - lib/pdfkit/middleware.rb
124
+ - lib/pdfkit/os.rb
134
125
  - lib/pdfkit/pdfkit.rb
135
126
  - lib/pdfkit/source.rb
136
127
  - lib/pdfkit/version.rb
128
+ - lib/pdfkit/wkhtmltopdf.rb
137
129
  - pdfkit.gemspec
138
130
  - spec/configuration_spec.rb
139
131
  - spec/fixtures/example.css
140
132
  - spec/fixtures/example.html
141
133
  - spec/fixtures/example_with_hex_symbol.css
134
+ - spec/html_preprocessor_spec.rb
142
135
  - spec/middleware_spec.rb
136
+ - spec/os_spec.rb
143
137
  - spec/pdfkit_spec.rb
144
138
  - spec/source_spec.rb
145
139
  - spec/spec_helper.rb
146
140
  homepage: https://github.com/pdfkit/pdfkit
147
- licenses: []
141
+ licenses:
142
+ - MIT
148
143
  metadata: {}
149
- post_install_message:
144
+ post_install_message:
150
145
  rdoc_options: []
151
146
  require_paths:
152
147
  - lib
153
148
  required_ruby_version: !ruby/object:Gem::Requirement
154
149
  requirements:
155
- - - '>='
150
+ - - ">="
156
151
  - !ruby/object:Gem::Version
157
- version: '0'
152
+ version: '2.5'
158
153
  required_rubygems_version: !ruby/object:Gem::Requirement
159
154
  requirements:
160
- - - '>='
155
+ - - ">="
161
156
  - !ruby/object:Gem::Version
162
157
  version: '0'
163
- requirements: []
164
- rubyforge_project: pdfkit
165
- rubygems_version: 2.4.6
166
- signing_key:
158
+ requirements:
159
+ - wkhtmltopdf
160
+ rubygems_version: 3.0.3.1
161
+ signing_key:
167
162
  specification_version: 4
168
163
  summary: HTML+CSS -> PDF
169
164
  test_files:
@@ -171,7 +166,9 @@ test_files:
171
166
  - spec/fixtures/example.css
172
167
  - spec/fixtures/example.html
173
168
  - spec/fixtures/example_with_hex_symbol.css
169
+ - spec/html_preprocessor_spec.rb
174
170
  - spec/middleware_spec.rb
171
+ - spec/os_spec.rb
175
172
  - spec/pdfkit_spec.rb
176
173
  - spec/source_spec.rb
177
174
  - spec/spec_helper.rb