pdfkit 0.8.5 → 0.8.7

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.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 709b9d124eeb6e972d0095d078ce39be54ef3335eb57b4042cc5499a423ac3ba
4
- data.tar.gz: 7de22b6ec750dc0f4aebe1f0c58b871cba29253a455310b9cc00b5915627ccce
3
+ metadata.gz: 824738b3d4f198d080bb590e5db7489da39ffb40f5f8c24b97652793160ac0d9
4
+ data.tar.gz: 963701136ddf00dd42502b2d564135c675ae1ae313c6cd40d8dd92761a70b3af
5
5
  SHA512:
6
- metadata.gz: c76d4d622db3fa8250aa396d5782e6b04d3569da187a740fd600b757956226514c01ccee0ab4e9ffc0d1e9ee828a50efb37d92109aa7a461b0ff0de2e2cdf0e6
7
- data.tar.gz: a09547f979b4742c9e4d2ddf898fea4ead8c86906ed89c100cbd476c1f022db46ecb3e0d7c6fa614c3f4ea5173699678d5621230706ad0ea3527ef3968b5a989
6
+ metadata.gz: 6340e287849a0c43b8883cc1f2b78138fc5628fd2da4670c5f5d8a150632b56dbf27c9716bea49c1007cc2359148a4b3c1af1fed8c264ff89cf3d379976bfe30
7
+ data.tar.gz: b1b4f6d302ec4c407ebac2dfcc6bf3d72d7882520ba407bdb0d2b0316684ddcc09d3eecf0967305976292210a21304dc9b399fa39a9c4055ced27c5b7b8c1677
@@ -12,8 +12,8 @@ jobs:
12
12
  steps:
13
13
  # Drafts your next Release notes as Pull Requests are merged into "master"
14
14
  - uses: release-drafter/release-drafter@v5
15
- with:
15
+ # with:
16
16
  # (Optional) specify config name to use, relative to .github/. Default: release-drafter.yml
17
17
  # config-name: my-config.yml
18
18
  env:
19
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
19
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -0,0 +1,59 @@
1
+ name: Test workflow
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ test:
7
+ strategy:
8
+ fail-fast: false
9
+ matrix:
10
+ os: [ubuntu-latest]
11
+ ruby:
12
+ - '2.5'
13
+ - '2.6'
14
+ - '2.7'
15
+ - '3.0'
16
+ - '3.1'
17
+ rails:
18
+ - '~> 4.1'
19
+ - '~> 5.2'
20
+ - '~> 6.0.0'
21
+ - '~> 6.1'
22
+ - '~> 7.0.0'
23
+ exclude:
24
+ - ruby: '2.5'
25
+ rails: '~> 7.0.0'
26
+ - ruby: '2.6'
27
+ rails: '~> 7.0.0'
28
+ - ruby: '2.7'
29
+ rails: '~> 4.1'
30
+ - ruby: '3.0'
31
+ rails: '~> 4.1'
32
+ - ruby: '3.0'
33
+ rails: '~> 5.2'
34
+ - ruby: '3.1'
35
+ rails: '~> 4.1'
36
+ - ruby: '3.1'
37
+ rails: '~> 5.2'
38
+ - ruby: '3.1'
39
+ rails: '~> 6.0.0'
40
+ runs-on: ${{ matrix.os }}
41
+ env:
42
+ RAILS_VERSION: ${{ matrix.rails }}
43
+ steps:
44
+ - uses: actions/checkout@v2
45
+ - uses: ruby/setup-ruby@v1
46
+ with:
47
+ ruby-version: ${{ matrix.ruby }}
48
+ rubygems: latest
49
+ bundler: latest
50
+ bundler-cache: true
51
+
52
+ - name: Setup wkhtmltopdf
53
+ run: |
54
+ sudo apt-get install -y xfonts-base xfonts-75dpi
55
+ wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.bionic_amd64.deb
56
+ sudo dpkg -i wkhtmltox_0.12.6-1.bionic_amd64.deb
57
+
58
+ - name: Run tests
59
+ run: bundle exec rake
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.6.4
1
+ 2.6.9
data/.travis.yml CHANGED
@@ -3,12 +3,38 @@ language: ruby
3
3
  rvm:
4
4
  - 2.5
5
5
  - 2.6
6
+ - 2.7
7
+ - 3.0
8
+ - 3.1
6
9
 
7
10
  env:
8
11
  matrix:
9
12
  - RAILS_VERSION="~> 4.1"
10
13
  - RAILS_VERSION="~> 5.2"
11
14
  - RAILS_VERSION="~> 6.0.0"
15
+ - RAILS_VERSION="~> 6.1"
16
+ - RAILS_VERSION="~> 7.0.0"
17
+
18
+ jobs:
19
+ exclude:
20
+ - rvm: 2.5
21
+ env: RAILS_VERSION="~> 7.0.0"
22
+ - rvm: 2.6
23
+ env: RAILS_VERSION="~> 7.0.0"
24
+ - rvm: 2.7
25
+ env: RAILS_VERSION="~> 4.1"
26
+ - rvm: 3.0
27
+ env: RAILS_VERSION="~> 4.1"
28
+ - rvm: 3.0
29
+ env: RAILS_VERSION="~> 5.2"
30
+ - rvm: 3.1
31
+ env: RAILS_VERSION="~> 4.1"
32
+ - rvm: 3.1
33
+ env: RAILS_VERSION="~> 5.2"
34
+ - rvm: 3.1
35
+ env: RAILS_VERSION="~> 6.0.0"
36
+
37
+ cache: bundler
12
38
 
13
39
  before_install:
14
40
  - gem update --system
data/CHANGELOG.md CHANGED
@@ -1,3 +1,14 @@
1
+ 2022-10-02
2
+ =================
3
+ * Bump to 0.8.7
4
+ * Lowercase the header names for rack 3 changes (#511)
5
+ * Partially escaped URLs should be escaped (#509)
6
+
7
+ 2022-04-11
8
+ =================
9
+ * Bump to 0.8.6
10
+ * Update ruby and rails versions
11
+
1
12
  2021-01-23
2
13
  =================
3
14
  * Bump to 0.8.5
data/README.md CHANGED
@@ -4,8 +4,8 @@ Create PDFs using plain old HTML+CSS. Uses [wkhtmltopdf](http://github.com/antia
4
4
 
5
5
  ## Supported versions
6
6
 
7
- - Ruby 2.5, 2.6
8
- - Rails 4.2, 5.2, 6.0
7
+ - Ruby 2.5, 2.6, 2.7, 3.0, 3.1
8
+ - Rails 4.2, 5.2, 6.0, 6.1, 7.0
9
9
 
10
10
  ## Install
11
11
 
@@ -63,7 +63,7 @@ PDFKit.new(html, protocol: 'https').to_file
63
63
  ```
64
64
 
65
65
  ### Using cookies in scraping
66
- If you want to pass a cookie to cookie to pdfkit to scrape a website, you can
66
+ If you want to pass a cookie to pdfkit to scrape a website, you can
67
67
  pass it in a hash:
68
68
  ```ruby
69
69
  kit = PDFKit.new(url, cookie: {cookie_name: :cookie_value})
@@ -172,7 +172,7 @@ Will cause the .pdf to be saved to `path/to/saved.pdf` in addition to being sent
172
172
  asset host.
173
173
 
174
174
  * **Mangled output in the browser:** Be sure that your HTTP response
175
- headers specify "Content-Type: application/pdf"
175
+ headers specify "content-type: application/pdf"
176
176
 
177
177
  ## Note on Patches/Pull Requests
178
178
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class PDFKit
2
4
  class Configuration
3
5
  attr_accessor :meta_tag_prefix, :root_url
@@ -26,7 +28,7 @@ class PDFKit
26
28
 
27
29
  def default_wkhtmltopdf
28
30
  return @default_command_path if @default_command_path
29
- if defined?(Bundler::GemfileError) && File.exists?('Gemfile')
31
+ if defined?(Bundler::GemfileError) && File.exist?('Gemfile')
30
32
  @default_command_path = `bundle exec which wkhtmltopdf`.chomp.lines.last
31
33
  end
32
34
  @default_command_path = `which wkhtmltopdf`.chomp if @default_command_path.nil? || @default_command_path.empty?
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class PDFKit
2
4
  module HTMLPreprocessor
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class PDFKit
2
4
  class Middleware
3
5
  def initialize(app, options = {}, conditions = {})
@@ -20,7 +22,7 @@ class PDFKit
20
22
  status, headers, response = @app.call(env)
21
23
 
22
24
  begin
23
- if rendering_pdf? && headers['Content-Type'] =~ /text\/html|application\/xhtml\+xml/
25
+ if rendering_pdf? && headers['content-type'] =~ /text\/html|application\/xhtml\+xml/
24
26
  body = response.respond_to?(:body) ? response.body : response.join
25
27
  body = body.join if body.is_a?(Array)
26
28
 
@@ -42,13 +44,13 @@ class PDFKit
42
44
 
43
45
  unless @caching
44
46
  # Do not cache PDFs
45
- headers.delete('ETag')
46
- headers.delete('Cache-Control')
47
+ headers.delete('etag')
48
+ headers.delete('cache-control')
47
49
  end
48
50
 
49
- headers['Content-Length'] = (body.respond_to?(:bytesize) ? body.bytesize : body.size).to_s
50
- headers['Content-Type'] = 'application/pdf'
51
- headers['Content-Disposition'] ||= @conditions[:disposition] || 'inline'
51
+ headers['content-length'] = (body.respond_to?(:bytesize) ? body.bytesize : body.size).to_s
52
+ headers['content-type'] = 'application/pdf'
53
+ headers['content-disposition'] ||= @conditions[:disposition] || 'inline'
52
54
  end
53
55
  rescue StandardError => e
54
56
  status = 500
data/lib/pdfkit/os.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rbconfig'
2
4
 
3
5
  class PDFKit
data/lib/pdfkit/pdfkit.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'shellwords'
2
4
  require 'tempfile'
3
5
 
@@ -6,8 +8,8 @@ class PDFKit
6
8
 
7
9
  class NoExecutableError < Error
8
10
  def initialize
9
- msg = "No wkhtmltopdf executable found at #{PDFKit.configuration.wkhtmltopdf}\n"
10
- msg << ">> Please install wkhtmltopdf - https://github.com/pdfkit/PDFKit/wiki/Installing-WKHTMLTOPDF"
11
+ msg = "No wkhtmltopdf executable found at #{PDFKit.configuration.wkhtmltopdf}\n" \
12
+ ">> Please install wkhtmltopdf - https://github.com/pdfkit/PDFKit/wiki/Installing-WKHTMLTOPDF"
11
13
  super(msg)
12
14
  end
13
15
  end
@@ -40,7 +42,7 @@ class PDFKit
40
42
  @renderer = WkHTMLtoPDF.new options
41
43
  @renderer.normalize_options
42
44
 
43
- raise NoExecutableError unless File.exists?(PDFKit.configuration.wkhtmltopdf)
45
+ raise NoExecutableError unless File.exist?(PDFKit.configuration.wkhtmltopdf)
44
46
  end
45
47
 
46
48
  def command(path = nil)
data/lib/pdfkit/source.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'tempfile'
2
4
  require 'uri'
3
5
 
@@ -7,6 +9,8 @@ class PDFKit
7
9
 
8
10
  def initialize(url_file_or_html)
9
11
  @source = url_file_or_html
12
+ # @source is assumed to be modifiable, so make sure it is.
13
+ @source = @source.dup if @source.is_a?(String) && @source.frozen?
10
14
  end
11
15
 
12
16
  def url?
@@ -38,11 +42,11 @@ class PDFKit
38
42
  private
39
43
 
40
44
  def shell_safe_url
41
- url_needs_escaping? ? URI::escape(@source) : @source
45
+ url_needs_escaping? ? URI::DEFAULT_PARSER.escape(@source) : @source
42
46
  end
43
47
 
44
48
  def url_needs_escaping?
45
- URI::decode(@source) == @source
49
+ URI::DEFAULT_PARSER.escape(URI::DEFAULT_PARSER.unescape(@source)) != @source
46
50
  end
47
51
  end
48
52
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class PDFKit
2
- VERSION = '0.8.5'
4
+ VERSION = '0.8.7'
3
5
  end
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class PDFKit
2
4
  class WkHTMLtoPDF
3
5
  attr_reader :options
4
6
  # Pulled from:
5
7
  # https://github.com/wkhtmltopdf/wkhtmltopdf/blob/ebf9b6cfc4c58a31349fb94c568b254fac37b3d3/README_WKHTMLTOIMAGE#L27
6
- REPEATABLE_OPTIONS = %w[--allow --cookie --custom-header --post --post-file --run-script]
7
- SPECIAL_OPTIONS = %w[cover toc]
8
+ REPEATABLE_OPTIONS = %w[--allow --cookie --custom-header --post --post-file --run-script].freeze
9
+ SPECIAL_OPTIONS = %w[cover toc].freeze
8
10
 
9
11
  def initialize(options)
10
12
  @options = options
data/lib/pdfkit.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'pdfkit/source'
2
4
  require 'pdfkit/pdfkit'
3
5
  require 'pdfkit/middleware'
data/pdfkit.gemspec CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
18
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
19
  s.require_paths = ["lib"]
20
20
 
21
- s.required_ruby_version = '>= 2.5'
21
+ s.required_ruby_version = ">= 2.5"
22
22
 
23
23
  s.requirements << "wkhtmltopdf"
24
24
 
@@ -26,7 +26,7 @@ Gem::Specification.new do |s|
26
26
  s.add_development_dependency(%q<activesupport>, [">= 4.1.11"])
27
27
  s.add_development_dependency(%q<mocha>, [">= 0.9.10"])
28
28
  s.add_development_dependency(%q<rack-test>, [">= 0.5.6"])
29
- s.add_development_dependency(%q<rake>, ["~>12.3.3"])
30
- s.add_development_dependency(%q<rdoc>, ["~> 4.0.1"])
29
+ s.add_development_dependency(%q<rake>, [">= 12.3.3"])
30
+ s.add_development_dependency(%q<rdoc>, [">= 4.0.1"])
31
31
  s.add_development_dependency(%q<rspec>, ["~> 3.0"])
32
32
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe PDFKit::Configuration do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe PDFKit::HTMLPreprocessor do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  def app; Rack::Lint.new(@app); end
@@ -17,7 +19,7 @@ end
17
19
 
18
20
  describe PDFKit::Middleware do
19
21
  let(:headers) do
20
- {'Content-Type' => "text/html"}
22
+ {'content-type' => "text/html"}
21
23
  end
22
24
 
23
25
  describe "#call" do
@@ -53,36 +55,36 @@ describe PDFKit::Middleware do
53
55
  describe "caching" do
54
56
  let(:headers) do
55
57
  {
56
- 'Content-Type' => "text/html",
57
- 'ETag' => 'foo',
58
- 'Cache-Control' => 'max-age=2592000, public'
58
+ 'content-type' => "text/html",
59
+ 'etag' => 'foo',
60
+ 'cache-control' => 'max-age=2592000, public'
59
61
  }
60
62
  end
61
63
 
62
64
  context "by default" do
63
65
  before { mock_app }
64
66
 
65
- it "deletes ETag" do
67
+ it "deletes etag" do
66
68
  get 'http://www.example.org/public/test.pdf'
67
- expect(last_response.headers["ETag"]).to be_nil
69
+ expect(last_response.headers["etag"]).to be_nil
68
70
  end
69
- it "deletes Cache-Control" do
71
+ it "deletes cache-control" do
70
72
  get 'http://www.example.org/public/test.pdf'
71
- expect(last_response.headers["Cache-Control"]).to be_nil
73
+ expect(last_response.headers["cache-control"]).to be_nil
72
74
  end
73
75
  end
74
76
 
75
77
  context "when on" do
76
78
  before { mock_app({}, :caching => true) }
77
79
 
78
- it "preserves ETag" do
80
+ it "preserves etag" do
79
81
  get 'http://www.example.org/public/test.pdf'
80
- expect(last_response.headers["ETag"]).not_to be_nil
82
+ expect(last_response.headers["etag"]).not_to be_nil
81
83
  end
82
84
 
83
- it "preserves Cache-Control" do
85
+ it "preserves cache-control" do
84
86
  get 'http://www.example.org/public/test.pdf'
85
- expect(last_response.headers["Cache-Control"]).not_to be_nil
87
+ expect(last_response.headers["cache-control"]).not_to be_nil
86
88
  end
87
89
  end
88
90
  end
@@ -97,7 +99,7 @@ describe PDFKit::Middleware do
97
99
  context "matching" do
98
100
  specify do
99
101
  get 'http://www.example.org/public/test.pdf'
100
- expect(last_response.headers["Content-Type"]).to eq("application/pdf")
102
+ expect(last_response.headers["content-type"]).to eq("application/pdf")
101
103
  expect(last_response.body.bytesize).to eq(PDFKit.new("Hello world!").to_pdf.bytesize)
102
104
  end
103
105
  end
@@ -105,7 +107,7 @@ describe PDFKit::Middleware do
105
107
  context "not matching" do
106
108
  specify do
107
109
  get 'http://www.example.org/secret/test.pdf'
108
- expect(last_response.headers["Content-Type"]).to eq("text/html")
110
+ expect(last_response.headers["content-type"]).to eq("text/html")
109
111
  expect(last_response.body).to eq("Hello world!")
110
112
  end
111
113
  end
@@ -117,7 +119,7 @@ describe PDFKit::Middleware do
117
119
  context "matching" do
118
120
  specify do
119
121
  get 'http://www.example.org/public/test.pdf'
120
- expect(last_response.headers["Content-Type"]).to eq("application/pdf")
122
+ expect(last_response.headers["content-type"]).to eq("application/pdf")
121
123
  expect(last_response.body.bytesize).to eq(PDFKit.new("Hello world!").to_pdf.bytesize)
122
124
  end
123
125
  end
@@ -125,7 +127,7 @@ describe PDFKit::Middleware do
125
127
  context "not matching" do
126
128
  specify do
127
129
  get 'http://www.example.org/secret/test.pdf'
128
- expect(last_response.headers["Content-Type"]).to eq("text/html")
130
+ expect(last_response.headers["content-type"]).to eq("text/html")
129
131
  expect(last_response.body).to eq("Hello world!")
130
132
  end
131
133
  end
@@ -139,7 +141,7 @@ describe PDFKit::Middleware do
139
141
  context "matching" do
140
142
  specify do
141
143
  get 'http://www.example.org/public/test.pdf'
142
- expect(last_response.headers["Content-Type"]).to eq("application/pdf")
144
+ expect(last_response.headers["content-type"]).to eq("application/pdf")
143
145
  expect(last_response.body.bytesize).to eq(PDFKit.new("Hello world!").to_pdf.bytesize)
144
146
  end
145
147
  end
@@ -147,7 +149,7 @@ describe PDFKit::Middleware do
147
149
  context "not matching" do
148
150
  specify do
149
151
  get 'http://www.example.org/secret/test.pdf'
150
- expect(last_response.headers["Content-Type"]).to eq("text/html")
152
+ expect(last_response.headers["content-type"]).to eq("text/html")
151
153
  expect(last_response.body).to eq("Hello world!")
152
154
  end
153
155
  end
@@ -159,7 +161,7 @@ describe PDFKit::Middleware do
159
161
  context "matching" do
160
162
  specify do
161
163
  get 'http://www.example.org/public/test.pdf'
162
- expect(last_response.headers["Content-Type"]).to eq("application/pdf")
164
+ expect(last_response.headers["content-type"]).to eq("application/pdf")
163
165
  expect(last_response.body.bytesize).to eq(PDFKit.new("Hello world!").to_pdf.bytesize)
164
166
  end
165
167
  end
@@ -167,7 +169,7 @@ describe PDFKit::Middleware do
167
169
  context "not matching" do
168
170
  specify do
169
171
  get 'http://www.example.org/secret/test.pdf'
170
- expect(last_response.headers["Content-Type"]).to eq("text/html")
172
+ expect(last_response.headers["content-type"]).to eq("text/html")
171
173
  expect(last_response.body).to eq("Hello world!")
172
174
  end
173
175
  end
@@ -185,7 +187,7 @@ describe PDFKit::Middleware do
185
187
  context "matching" do
186
188
  specify do
187
189
  get 'http://www.example.org/public/test.pdf'
188
- expect(last_response.headers["Content-Type"]).to eq("application/pdf")
190
+ expect(last_response.headers["content-type"]).to eq("application/pdf")
189
191
  expect(last_response.body.bytesize).to eq(PDFKit.new("Hello world!").to_pdf.bytesize)
190
192
  end
191
193
  end
@@ -193,7 +195,7 @@ describe PDFKit::Middleware do
193
195
  context "not matching" do
194
196
  specify do
195
197
  get 'http://www.example.org/secret/test.pdf'
196
- expect(last_response.headers["Content-Type"]).to eq("text/html")
198
+ expect(last_response.headers["content-type"]).to eq("text/html")
197
199
  expect(last_response.body).to eq("Hello world!")
198
200
  end
199
201
  end
@@ -205,7 +207,7 @@ describe PDFKit::Middleware do
205
207
  context "matching" do
206
208
  specify do
207
209
  get 'http://www.example.org/public/test.pdf'
208
- expect(last_response.headers["Content-Type"]).to eq("application/pdf")
210
+ expect(last_response.headers["content-type"]).to eq("application/pdf")
209
211
  expect(last_response.body.bytesize).to eq(PDFKit.new("Hello world!").to_pdf.bytesize)
210
212
  end
211
213
  end
@@ -213,7 +215,7 @@ describe PDFKit::Middleware do
213
215
  context "not matching" do
214
216
  specify do
215
217
  get 'http://www.example.org/secret/test.pdf'
216
- expect(last_response.headers["Content-Type"]).to eq("text/html")
218
+ expect(last_response.headers["content-type"]).to eq("text/html")
217
219
  expect(last_response.body).to eq("Hello world!")
218
220
  end
219
221
  end
@@ -227,7 +229,7 @@ describe PDFKit::Middleware do
227
229
  context "matching" do
228
230
  specify do
229
231
  get 'http://www.example.org/public/test.pdf'
230
- expect(last_response.headers["Content-Type"]).to eq("application/pdf")
232
+ expect(last_response.headers["content-type"]).to eq("application/pdf")
231
233
  expect(last_response.body.bytesize).to eq(PDFKit.new("Hello world!").to_pdf.bytesize)
232
234
  end
233
235
  end
@@ -235,7 +237,7 @@ describe PDFKit::Middleware do
235
237
  context "not matching" do
236
238
  specify do
237
239
  get 'http://www.example.org/secret/test.pdf'
238
- expect(last_response.headers["Content-Type"]).to eq("text/html")
240
+ expect(last_response.headers["content-type"]).to eq("text/html")
239
241
  expect(last_response.body).to eq("Hello world!")
240
242
  end
241
243
  end
@@ -247,7 +249,7 @@ describe PDFKit::Middleware do
247
249
  context "matching" do
248
250
  specify do
249
251
  get 'http://www.example.org/public/test.pdf'
250
- expect(last_response.headers["Content-Type"]).to eq("application/pdf")
252
+ expect(last_response.headers["content-type"]).to eq("application/pdf")
251
253
  expect(last_response.body.bytesize).to eq(PDFKit.new("Hello world!").to_pdf.bytesize)
252
254
  end
253
255
  end
@@ -255,7 +257,7 @@ describe PDFKit::Middleware do
255
257
  context "not matching" do
256
258
  specify do
257
259
  get 'http://www.example.org/secret/test.pdf'
258
- expect(last_response.headers["Content-Type"]).to eq("text/html")
260
+ expect(last_response.headers["content-type"]).to eq("text/html")
259
261
  expect(last_response.body).to eq("Hello world!")
260
262
  end
261
263
  end
@@ -267,8 +269,8 @@ describe PDFKit::Middleware do
267
269
  describe "saving generated pdf to disk" do
268
270
  before do
269
271
  #make sure tests don't find an old test_save.pdf
270
- File.delete('spec/test_save.pdf') if File.exists?('spec/test_save.pdf')
271
- expect(File.exists?('spec/test_save.pdf')).to eq(false)
272
+ File.delete('spec/test_save.pdf') if File.exist?('spec/test_save.pdf')
273
+ expect(File.exist?('spec/test_save.pdf')).to eq(false)
272
274
  end
273
275
 
274
276
  context "when header PDFKit-save-pdf is present" do
@@ -276,7 +278,7 @@ describe PDFKit::Middleware do
276
278
  headers = { 'PDFKit-save-pdf' => 'spec/test_save.pdf' }
277
279
  mock_app({}, {only: '/public'}, headers)
278
280
  get 'http://www.example.org/public/test_save.pdf'
279
- expect(File.exists?('spec/test_save.pdf')).to eq(true)
281
+ expect(File.exist?('spec/test_save.pdf')).to eq(true)
280
282
  end
281
283
 
282
284
  it "does not raise when target directory does not exist" do
@@ -292,7 +294,7 @@ describe PDFKit::Middleware do
292
294
  it "does not saved the .pdf to disk" do
293
295
  mock_app({}, {only: '/public'}, {} )
294
296
  get 'http://www.example.org/public/test_save.pdf'
295
- expect(File.exists?('spec/test_save.pdf')).to eq(false)
297
+ expect(File.exist?('spec/test_save.pdf')).to eq(false)
296
298
  end
297
299
  end
298
300
  end
@@ -346,14 +348,14 @@ describe PDFKit::Middleware do
346
348
  describe "doesn't overwrite existing value" do
347
349
  let(:headers) do
348
350
  super().merge({
349
- 'Content-Disposition' => 'attachment; filename=report-20200101.pdf'
351
+ 'content-disposition' => 'attachment; filename=report-20200101.pdf'
350
352
  })
351
353
  end
352
354
 
353
355
  specify do
354
356
  mock_app({}, { :disposition => 'inline' })
355
357
  get 'http://www.example.org/public/test.pdf'
356
- expect(last_response.headers["Content-Disposition"]).to eq('attachment; filename=report-20200101.pdf')
358
+ expect(last_response.headers["content-disposition"]).to eq('attachment; filename=report-20200101.pdf')
357
359
  end
358
360
  end
359
361
 
@@ -362,7 +364,7 @@ describe PDFKit::Middleware do
362
364
  specify do
363
365
  mock_app
364
366
  get 'http://www.example.org/public/test.pdf'
365
- expect(last_response.headers["Content-Disposition"]).to eq("inline")
367
+ expect(last_response.headers["content-disposition"]).to eq("inline")
366
368
  end
367
369
  end
368
370
 
@@ -370,7 +372,7 @@ describe PDFKit::Middleware do
370
372
  specify do
371
373
  mock_app({}, { :disposition => 'inline' })
372
374
  get 'http://www.example.org/public/test.pdf'
373
- expect(last_response.headers["Content-Disposition"]).to eq("inline")
375
+ expect(last_response.headers["content-disposition"]).to eq("inline")
374
376
  end
375
377
  end
376
378
  end
@@ -380,7 +382,7 @@ describe PDFKit::Middleware do
380
382
  specify do
381
383
  mock_app({}, { :disposition => 'attachment' })
382
384
  get 'http://www.example.org/public/test.pdf'
383
- expect(last_response.headers["Content-Disposition"]).to eq("attachment")
385
+ expect(last_response.headers["content-disposition"]).to eq("attachment")
384
386
  end
385
387
  end
386
388
 
@@ -388,7 +390,7 @@ describe PDFKit::Middleware do
388
390
  specify do
389
391
  mock_app({}, { :disposition => 'attachment; filename=report.pdf' })
390
392
  get 'http://www.example.org/public/test.pdf'
391
- expect(last_response.headers["Content-Disposition"]).to eq("attachment; filename=report.pdf")
393
+ expect(last_response.headers["content-disposition"]).to eq("attachment; filename=report.pdf")
392
394
  end
393
395
  end
394
396
  end
@@ -444,7 +446,7 @@ describe PDFKit::Middleware do
444
446
  main_app = lambda { |env|
445
447
  @env = env
446
448
  @env['SCRIPT_NAME'] = '/example.org'
447
- headers = {'Content-Type' => "text/html"}
449
+ headers = {'content-type' => "text/html"}
448
450
  [200, headers, @body || ['Hello world!']]
449
451
  }
450
452
 
data/spec/os_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
  require 'rbconfig'
4
6
 
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
@@ -27,7 +29,7 @@ describe PDFKit do
27
29
  file_path = File.join(SPEC_ROOT,'fixtures','example.html')
28
30
  pdfkit = PDFKit.new(Tempfile.new(file_path))
29
31
  expect(pdfkit.source).to be_file
30
- expect(pdfkit.source.to_s).to match /^#{Dir.tmpdir}/
32
+ expect(pdfkit.source.to_s).to match(/^#{Dir.tmpdir}/)
31
33
  end
32
34
 
33
35
  # Options
@@ -239,12 +241,12 @@ describe PDFKit do
239
241
 
240
242
  it "read the source from stdin if it is html" do
241
243
  pdfkit = PDFKit.new('html')
242
- expect(pdfkit.command).to match /- -$/
244
+ expect(pdfkit.command).to match(/- -$/)
243
245
  end
244
246
 
245
247
  it "specifies the URL to the source if it is a url" do
246
248
  pdfkit = PDFKit.new('http://google.com')
247
- expect(pdfkit.command).to match /"http:\/\/google.com" -$/
249
+ expect(pdfkit.command).to match(/"http:\/\/google.com" -$/)
248
250
  end
249
251
 
250
252
  it "does not break Windows paths" do
@@ -256,19 +258,19 @@ describe PDFKit do
256
258
  it "specifies the path to the source if it is a file" do
257
259
  file_path = File.join(SPEC_ROOT,'fixtures','example.html')
258
260
  pdfkit = PDFKit.new(File.new(file_path))
259
- expect(pdfkit.command).to match /#{file_path} -$/
261
+ expect(pdfkit.command).to match(/#{file_path} -$/)
260
262
  end
261
263
 
262
264
  it "specifies the path to the source if it is a tempfile" do
263
265
  file_path = File.join(SPEC_ROOT,'fixtures','example.html')
264
266
  pdfkit = PDFKit.new(Tempfile.new(file_path))
265
- expect(pdfkit.command).to match /#{Dir.tmpdir}\S+ -$/
267
+ expect(pdfkit.command).to match(/#{Dir.tmpdir}\S+ -$/)
266
268
  end
267
269
 
268
270
  it "specifies the path for the ouput if a path is given" do
269
271
  file_path = "/path/to/output.pdf"
270
272
  pdfkit = PDFKit.new("html")
271
- expect(pdfkit.command(file_path)).to match /#{file_path}$/
273
+ expect(pdfkit.command(file_path)).to match(/#{file_path}$/)
272
274
  end
273
275
 
274
276
  it "detects special pdfkit meta tags" 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
@@ -78,6 +80,11 @@ describe PDFKit::Source do
78
80
  expect(source.to_input_for_command).to eq "\"https://www.google.com/search?q='cat%3Cdev/zero%3E/dev/null'\""
79
81
  end
80
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
+
81
88
  it "does not URI escape previously escaped source URLs" do
82
89
  source = PDFKit::Source.new("https://www.google.com/search?q='cat%3Cdev/zero%3E/dev/null'")
83
90
  expect(source.to_input_for_command).to eq "\"https://www.google.com/search?q='cat%3Cdev/zero%3E/dev/null'\""
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,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pdfkit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.5
4
+ version: 0.8.7
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: 2021-01-24 00:00:00.000000000 Z
12
+ date: 2022-10-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -57,28 +57,28 @@ dependencies:
57
57
  name: rake
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
- - - "~>"
60
+ - - ">="
61
61
  - !ruby/object:Gem::Version
62
62
  version: 12.3.3
63
63
  type: :development
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
- - - "~>"
67
+ - - ">="
68
68
  - !ruby/object:Gem::Version
69
69
  version: 12.3.3
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: rdoc
72
72
  requirement: !ruby/object:Gem::Requirement
73
73
  requirements:
74
- - - "~>"
74
+ - - ">="
75
75
  - !ruby/object:Gem::Version
76
76
  version: 4.0.1
77
77
  type: :development
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
81
- - - "~>"
81
+ - - ">="
82
82
  - !ruby/object:Gem::Version
83
83
  version: 4.0.1
84
84
  - !ruby/object:Gem::Dependency
@@ -105,6 +105,7 @@ files:
105
105
  - ".document"
106
106
  - ".github/workflows/release-drafter.yml"
107
107
  - ".github/workflows/stale.yml"
108
+ - ".github/workflows/test.yml"
108
109
  - ".gitignore"
109
110
  - ".rspec"
110
111
  - ".ruby-gemset"
@@ -140,7 +141,7 @@ homepage: https://github.com/pdfkit/pdfkit
140
141
  licenses:
141
142
  - MIT
142
143
  metadata: {}
143
- post_install_message:
144
+ post_install_message:
144
145
  rdoc_options: []
145
146
  require_paths:
146
147
  - lib
@@ -156,8 +157,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
156
157
  version: '0'
157
158
  requirements:
158
159
  - wkhtmltopdf
159
- rubygems_version: 3.0.3
160
- signing_key:
160
+ rubygems_version: 3.0.3.1
161
+ signing_key:
161
162
  specification_version: 4
162
163
  summary: HTML+CSS -> PDF
163
164
  test_files: