pdfkit 0.8.2 → 0.8.4.3.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.

@@ -0,0 +1,65 @@
1
+ #encoding: UTF-8
2
+ require 'spec_helper'
3
+ require 'rbconfig'
4
+
5
+ describe 'OS' do
6
+ subject { PDFKit::OS }
7
+
8
+ describe 'host_is_windows?' do
9
+ it 'is callable' do
10
+ expect(subject).to respond_to(:host_is_windows?)
11
+ end
12
+
13
+ def test_is_windows(bool, host_os)
14
+ allow(RbConfig::CONFIG).to receive(:[]).with('host_os').and_return(host_os)
15
+
16
+ expect(subject.host_is_windows?).to be bool
17
+ end
18
+
19
+ it 'returns true if the host_os is set to "mswin"' do
20
+ test_is_windows(true, 'mswin')
21
+ end
22
+
23
+ it 'returns true if the host_os is set to "msys"' do
24
+ test_is_windows(true, 'msys')
25
+ end
26
+
27
+ it 'returns false if the host_os is set to "linux-gnu"' do
28
+ test_is_windows(false, 'linux-gnu')
29
+ end
30
+
31
+ it 'returns false if the host_os is set to "darwin14.1.0"' do
32
+ test_is_windows(false, 'darwin14.1.0')
33
+ end
34
+ end
35
+
36
+ describe 'shell_escape_for_os' do
37
+ it 'is callable' do
38
+ expect(subject).to respond_to(:shell_escape_for_os)
39
+ end
40
+
41
+ it 'calls shelljoin on linux' do
42
+ args = double(:shelljoin)
43
+ allow(RbConfig::CONFIG).to receive(:[]).with('host_os').and_return('linux-gnu')
44
+
45
+ expect(args).to receive(:shelljoin)
46
+ PDFKit::OS.shell_escape_for_os(args)
47
+ end
48
+
49
+ it 'calls shelljoin on darwin14.1.10' do
50
+ args = double(:shelljoin)
51
+ allow(RbConfig::CONFIG).to receive(:[]).with('host_os').and_return('darwin14.1.10-gnu')
52
+
53
+ expect(args).to receive(:shelljoin)
54
+ PDFKit::OS.shell_escape_for_os(args)
55
+ end
56
+
57
+ it 'escapes special characters on Windows' do
58
+ args = ['foo|bar', 'biz(baz)', 'foo<baz>bar', 'hello^world&goodbye']
59
+ allow(RbConfig::CONFIG).to receive(:[]).with('host_os').and_return('mswin')
60
+
61
+ escaped_args = PDFKit::OS.shell_escape_for_os(args)
62
+ expect(escaped_args).to eq('foo^|bar biz^(baz^) foo^<baz^>bar hello^^world^&goodbye')
63
+ end
64
+ end
65
+ end
@@ -23,6 +23,13 @@ describe PDFKit do
23
23
  expect(pdfkit.source.to_s).to eq(file_path)
24
24
  end
25
25
 
26
+ it "accepts a Tempfile as the source" do
27
+ file_path = File.join(SPEC_ROOT,'fixtures','example.html')
28
+ pdfkit = PDFKit.new(Tempfile.new(file_path))
29
+ expect(pdfkit.source).to be_file
30
+ expect(pdfkit.source.to_s).to match /^#{Dir.tmpdir}/
31
+ end
32
+
26
33
  # Options
27
34
  ## options keys
28
35
  it "drops options without values" do
@@ -252,6 +259,12 @@ describe PDFKit do
252
259
  expect(pdfkit.command).to match /#{file_path} -$/
253
260
  end
254
261
 
262
+ it "specifies the path to the source if it is a tempfile" do
263
+ file_path = File.join(SPEC_ROOT,'fixtures','example.html')
264
+ pdfkit = PDFKit.new(Tempfile.new(file_path))
265
+ expect(pdfkit.command).to match /#{Dir.tmpdir}\S+ -$/
266
+ end
267
+
255
268
  it "specifies the path for the ouput if a path is given" do
256
269
  file_path = "/path/to/output.pdf"
257
270
  pdfkit = PDFKit.new("html")
@@ -384,9 +397,27 @@ describe PDFKit do
384
397
  end
385
398
  end
386
399
 
400
+ it "does not use xvfb-run wrapper by default" do
401
+ pdfkit = PDFKit.new('html')
402
+ expect(pdfkit.command).not_to include 'xvfb-run'
403
+ end
404
+
405
+ it "uses xvfb-run wrapper when option of using xvfb is configured" do
406
+ PDFKit.configure do |config|
407
+ config.use_xvfb = true
408
+ end
409
+
410
+ pdfkit = PDFKit.new('html')
411
+ expect(pdfkit.command).to include 'xvfb-run'
412
+
413
+ PDFKit.configure do |config|
414
+ config.use_xvfb = false
415
+ end
416
+ end
417
+
387
418
  context "on windows" do
388
419
  before do
389
- allow_any_instance_of(PDFKit).to receive(:host_is_windows?).and_return(true)
420
+ allow(PDFKit::OS).to receive(:host_is_windows?).and_return(true)
390
421
  end
391
422
 
392
423
  it "escapes special windows characters" do
@@ -481,7 +512,7 @@ describe PDFKit do
481
512
  #NOTICE: This test is failed if use wkhtmltopdf-binary (0.9.9.1)
482
513
  it "throws an error if it is unable to connect" do
483
514
  pdfkit = PDFKit.new("http://google.com/this-should-not-be-found/404.html")
484
- expect { pdfkit.to_pdf }.to raise_error /exitstatus=1/
515
+ expect { pdfkit.to_pdf }.to raise_error PDFKit::ImproperWkhtmltopdfExitStatus, /exitstatus=1/
485
516
  end
486
517
 
487
518
  it "does not throw an error if it is unable to connect", pending: 'this test works for wkhtmltopdf-binary (0.9.9.1)' do
@@ -12,6 +12,11 @@ describe PDFKit::Source do
12
12
  expect(source).not_to be_url
13
13
  end
14
14
 
15
+ it "returns false if passed a tempfile" do
16
+ source = PDFKit::Source.new(::Tempfile.new(__FILE__))
17
+ expect(source).not_to be_url
18
+ end
19
+
15
20
  it "returns false if passed HTML" do
16
21
  source = PDFKit::Source.new('<blink>Oh Hai!</blink>')
17
22
  expect(source).not_to be_url
@@ -29,6 +34,11 @@ describe PDFKit::Source do
29
34
  expect(source).to be_file
30
35
  end
31
36
 
37
+ it "returns true if passed a tempfile" do
38
+ source = PDFKit::Source.new(::Tempfile.new(__FILE__))
39
+ expect(source).to be_file
40
+ end
41
+
32
42
  it "returns false if passed a url like string" do
33
43
  source = PDFKit::Source.new('http://google.com')
34
44
  expect(source).not_to be_file
@@ -51,6 +61,11 @@ describe PDFKit::Source do
51
61
  expect(source).not_to be_html
52
62
  end
53
63
 
64
+ it "returns false if passed a tempfile" do
65
+ source = PDFKit::Source.new(::Tempfile.new(__FILE__))
66
+ expect(source).not_to be_html
67
+ end
68
+
54
69
  it "returns false if passed a url like string" do
55
70
  source = PDFKit::Source.new('http://google.com')
56
71
  expect(source).not_to be_html
@@ -77,6 +92,11 @@ describe PDFKit::Source do
77
92
  source = PDFKit::Source.new(::File.new(__FILE__))
78
93
  expect(source.to_input_for_command).to match 'spec/source_spec.rb'
79
94
  end
95
+
96
+ it "returns the file path for tempfile sources" do
97
+ source = PDFKit::Source.new(file = ::Tempfile.new(__FILE__))
98
+ expect(source.to_input_for_command).to match file.path
99
+ end
80
100
  end
81
101
 
82
102
  describe "#to_s" do
@@ -90,6 +110,11 @@ describe PDFKit::Source do
90
110
  expect(source.to_s).to eq(__FILE__)
91
111
  end
92
112
 
113
+ it "returns a path if passed a tempfile" do
114
+ source = PDFKit::Source.new(file = ::Tempfile.new(__FILE__))
115
+ expect(source.to_s).to eq(file.path)
116
+ end
117
+
93
118
  it "returns the url if passed a url like string" do
94
119
  source = PDFKit::Source.new('http://google.com')
95
120
  expect(source.to_s).to eq('http://google.com')
metadata CHANGED
@@ -1,7 +1,7 @@
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.4.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jared Pace
@@ -9,104 +9,90 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-08-26 00:00:00.000000000 Z
12
+ date: 2020-07-06 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,13 @@ 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/stale.yml"
107
+ - ".gitignore"
108
+ - ".rspec"
109
+ - ".ruby-gemset"
110
+ - ".ruby-version"
111
+ - ".travis.yml"
125
112
  - CHANGELOG.md
126
113
  - Gemfile
127
114
  - LICENSE
@@ -130,21 +117,27 @@ files:
130
117
  - Rakefile
131
118
  - lib/pdfkit.rb
132
119
  - lib/pdfkit/configuration.rb
120
+ - lib/pdfkit/html_preprocessor.rb
133
121
  - lib/pdfkit/middleware.rb
122
+ - lib/pdfkit/os.rb
134
123
  - lib/pdfkit/pdfkit.rb
135
124
  - lib/pdfkit/source.rb
136
125
  - lib/pdfkit/version.rb
126
+ - lib/pdfkit/wkhtmltopdf.rb
137
127
  - pdfkit.gemspec
138
128
  - spec/configuration_spec.rb
139
129
  - spec/fixtures/example.css
140
130
  - spec/fixtures/example.html
141
131
  - spec/fixtures/example_with_hex_symbol.css
132
+ - spec/html_preprocessor_spec.rb
142
133
  - spec/middleware_spec.rb
134
+ - spec/os_spec.rb
143
135
  - spec/pdfkit_spec.rb
144
136
  - spec/source_spec.rb
145
137
  - spec/spec_helper.rb
146
138
  homepage: https://github.com/pdfkit/pdfkit
147
- licenses: []
139
+ licenses:
140
+ - MIT
148
141
  metadata: {}
149
142
  post_install_message:
150
143
  rdoc_options: []
@@ -152,17 +145,17 @@ require_paths:
152
145
  - lib
153
146
  required_ruby_version: !ruby/object:Gem::Requirement
154
147
  requirements:
155
- - - '>='
148
+ - - ">="
156
149
  - !ruby/object:Gem::Version
157
150
  version: '0'
158
151
  required_rubygems_version: !ruby/object:Gem::Requirement
159
152
  requirements:
160
- - - '>='
153
+ - - ">="
161
154
  - !ruby/object:Gem::Version
162
155
  version: '0'
163
- requirements: []
164
- rubyforge_project: pdfkit
165
- rubygems_version: 2.4.6
156
+ requirements:
157
+ - wkhtmltopdf
158
+ rubygems_version: 3.0.3
166
159
  signing_key:
167
160
  specification_version: 4
168
161
  summary: HTML+CSS -> PDF
@@ -171,7 +164,9 @@ test_files:
171
164
  - spec/fixtures/example.css
172
165
  - spec/fixtures/example.html
173
166
  - spec/fixtures/example_with_hex_symbol.css
167
+ - spec/html_preprocessor_spec.rb
174
168
  - spec/middleware_spec.rb
169
+ - spec/os_spec.rb
175
170
  - spec/pdfkit_spec.rb
176
171
  - spec/source_spec.rb
177
172
  - spec/spec_helper.rb