pdfkit 0.8.6 → 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: 2c5255fcf07a7c382fc239a68a805d8a2950df682166a5913ca60c34bac9fe44
4
- data.tar.gz: 43555629ecdba193f051ab0ea10f025f7917acf558af58ea30ae69cac6f6b210
3
+ metadata.gz: 824738b3d4f198d080bb590e5db7489da39ffb40f5f8c24b97652793160ac0d9
4
+ data.tar.gz: 963701136ddf00dd42502b2d564135c675ae1ae313c6cd40d8dd92761a70b3af
5
5
  SHA512:
6
- metadata.gz: eb5f31eb9f0f84eb8d9b626c5c804f4f58ab0230b410740cad8810c4b0f673608ebb4874a0aa5f3fffade6c78b551e2a3fa339075fe0aad0f446117eb4af23bb
7
- data.tar.gz: a9e6dd403b4ec4795e9af96fd1d2e896d1d1cb497adaca1fd96044504877bf264dfd5cf3a161012430a5930aaf4921271b1ad4ee294ec1e357f3e39366ec6be3
6
+ metadata.gz: 6340e287849a0c43b8883cc1f2b78138fc5628fd2da4670c5f5d8a150632b56dbf27c9716bea49c1007cc2359148a4b3c1af1fed8c264ff89cf3d379976bfe30
7
+ data.tar.gz: b1b4f6d302ec4c407ebac2dfcc6bf3d72d7882520ba407bdb0d2b0316684ddcc09d3eecf0967305976292210a21304dc9b399fa39a9c4055ced27c5b7b8c1677
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
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
+
1
7
  2022-04-11
2
8
  =================
3
9
  * Bump to 0.8.6
data/README.md CHANGED
@@ -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
 
@@ -22,7 +22,7 @@ class PDFKit
22
22
  status, headers, response = @app.call(env)
23
23
 
24
24
  begin
25
- if rendering_pdf? && headers['Content-Type'] =~ /text\/html|application\/xhtml\+xml/
25
+ if rendering_pdf? && headers['content-type'] =~ /text\/html|application\/xhtml\+xml/
26
26
  body = response.respond_to?(:body) ? response.body : response.join
27
27
  body = body.join if body.is_a?(Array)
28
28
 
@@ -44,13 +44,13 @@ class PDFKit
44
44
 
45
45
  unless @caching
46
46
  # Do not cache PDFs
47
- headers.delete('ETag')
48
- headers.delete('Cache-Control')
47
+ headers.delete('etag')
48
+ headers.delete('cache-control')
49
49
  end
50
50
 
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'
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'
54
54
  end
55
55
  rescue StandardError => e
56
56
  status = 500
data/lib/pdfkit/source.rb CHANGED
@@ -46,7 +46,7 @@ class PDFKit
46
46
  end
47
47
 
48
48
  def url_needs_escaping?
49
- URI::DEFAULT_PARSER.unescape(@source) == @source
49
+ URI::DEFAULT_PARSER.escape(URI::DEFAULT_PARSER.unescape(@source)) != @source
50
50
  end
51
51
  end
52
52
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class PDFKit
4
- VERSION = '0.8.6'
4
+ VERSION = '0.8.7'
5
5
  end
@@ -19,7 +19,7 @@ end
19
19
 
20
20
  describe PDFKit::Middleware do
21
21
  let(:headers) do
22
- {'Content-Type' => "text/html"}
22
+ {'content-type' => "text/html"}
23
23
  end
24
24
 
25
25
  describe "#call" do
@@ -55,36 +55,36 @@ describe PDFKit::Middleware do
55
55
  describe "caching" do
56
56
  let(:headers) do
57
57
  {
58
- 'Content-Type' => "text/html",
59
- 'ETag' => 'foo',
60
- 'Cache-Control' => 'max-age=2592000, public'
58
+ 'content-type' => "text/html",
59
+ 'etag' => 'foo',
60
+ 'cache-control' => 'max-age=2592000, public'
61
61
  }
62
62
  end
63
63
 
64
64
  context "by default" do
65
65
  before { mock_app }
66
66
 
67
- it "deletes ETag" do
67
+ it "deletes etag" do
68
68
  get 'http://www.example.org/public/test.pdf'
69
- expect(last_response.headers["ETag"]).to be_nil
69
+ expect(last_response.headers["etag"]).to be_nil
70
70
  end
71
- it "deletes Cache-Control" do
71
+ it "deletes cache-control" do
72
72
  get 'http://www.example.org/public/test.pdf'
73
- expect(last_response.headers["Cache-Control"]).to be_nil
73
+ expect(last_response.headers["cache-control"]).to be_nil
74
74
  end
75
75
  end
76
76
 
77
77
  context "when on" do
78
78
  before { mock_app({}, :caching => true) }
79
79
 
80
- it "preserves ETag" do
80
+ it "preserves etag" do
81
81
  get 'http://www.example.org/public/test.pdf'
82
- expect(last_response.headers["ETag"]).not_to be_nil
82
+ expect(last_response.headers["etag"]).not_to be_nil
83
83
  end
84
84
 
85
- it "preserves Cache-Control" do
85
+ it "preserves cache-control" do
86
86
  get 'http://www.example.org/public/test.pdf'
87
- expect(last_response.headers["Cache-Control"]).not_to be_nil
87
+ expect(last_response.headers["cache-control"]).not_to be_nil
88
88
  end
89
89
  end
90
90
  end
@@ -99,7 +99,7 @@ describe PDFKit::Middleware do
99
99
  context "matching" do
100
100
  specify do
101
101
  get 'http://www.example.org/public/test.pdf'
102
- expect(last_response.headers["Content-Type"]).to eq("application/pdf")
102
+ expect(last_response.headers["content-type"]).to eq("application/pdf")
103
103
  expect(last_response.body.bytesize).to eq(PDFKit.new("Hello world!").to_pdf.bytesize)
104
104
  end
105
105
  end
@@ -107,7 +107,7 @@ describe PDFKit::Middleware do
107
107
  context "not matching" do
108
108
  specify do
109
109
  get 'http://www.example.org/secret/test.pdf'
110
- expect(last_response.headers["Content-Type"]).to eq("text/html")
110
+ expect(last_response.headers["content-type"]).to eq("text/html")
111
111
  expect(last_response.body).to eq("Hello world!")
112
112
  end
113
113
  end
@@ -119,7 +119,7 @@ describe PDFKit::Middleware do
119
119
  context "matching" do
120
120
  specify do
121
121
  get 'http://www.example.org/public/test.pdf'
122
- expect(last_response.headers["Content-Type"]).to eq("application/pdf")
122
+ expect(last_response.headers["content-type"]).to eq("application/pdf")
123
123
  expect(last_response.body.bytesize).to eq(PDFKit.new("Hello world!").to_pdf.bytesize)
124
124
  end
125
125
  end
@@ -127,7 +127,7 @@ describe PDFKit::Middleware do
127
127
  context "not matching" do
128
128
  specify do
129
129
  get 'http://www.example.org/secret/test.pdf'
130
- expect(last_response.headers["Content-Type"]).to eq("text/html")
130
+ expect(last_response.headers["content-type"]).to eq("text/html")
131
131
  expect(last_response.body).to eq("Hello world!")
132
132
  end
133
133
  end
@@ -141,7 +141,7 @@ describe PDFKit::Middleware do
141
141
  context "matching" do
142
142
  specify do
143
143
  get 'http://www.example.org/public/test.pdf'
144
- expect(last_response.headers["Content-Type"]).to eq("application/pdf")
144
+ expect(last_response.headers["content-type"]).to eq("application/pdf")
145
145
  expect(last_response.body.bytesize).to eq(PDFKit.new("Hello world!").to_pdf.bytesize)
146
146
  end
147
147
  end
@@ -149,7 +149,7 @@ describe PDFKit::Middleware do
149
149
  context "not matching" do
150
150
  specify do
151
151
  get 'http://www.example.org/secret/test.pdf'
152
- expect(last_response.headers["Content-Type"]).to eq("text/html")
152
+ expect(last_response.headers["content-type"]).to eq("text/html")
153
153
  expect(last_response.body).to eq("Hello world!")
154
154
  end
155
155
  end
@@ -161,7 +161,7 @@ describe PDFKit::Middleware do
161
161
  context "matching" do
162
162
  specify do
163
163
  get 'http://www.example.org/public/test.pdf'
164
- expect(last_response.headers["Content-Type"]).to eq("application/pdf")
164
+ expect(last_response.headers["content-type"]).to eq("application/pdf")
165
165
  expect(last_response.body.bytesize).to eq(PDFKit.new("Hello world!").to_pdf.bytesize)
166
166
  end
167
167
  end
@@ -169,7 +169,7 @@ describe PDFKit::Middleware do
169
169
  context "not matching" do
170
170
  specify do
171
171
  get 'http://www.example.org/secret/test.pdf'
172
- expect(last_response.headers["Content-Type"]).to eq("text/html")
172
+ expect(last_response.headers["content-type"]).to eq("text/html")
173
173
  expect(last_response.body).to eq("Hello world!")
174
174
  end
175
175
  end
@@ -187,7 +187,7 @@ describe PDFKit::Middleware do
187
187
  context "matching" do
188
188
  specify do
189
189
  get 'http://www.example.org/public/test.pdf'
190
- expect(last_response.headers["Content-Type"]).to eq("application/pdf")
190
+ expect(last_response.headers["content-type"]).to eq("application/pdf")
191
191
  expect(last_response.body.bytesize).to eq(PDFKit.new("Hello world!").to_pdf.bytesize)
192
192
  end
193
193
  end
@@ -195,7 +195,7 @@ describe PDFKit::Middleware do
195
195
  context "not matching" do
196
196
  specify do
197
197
  get 'http://www.example.org/secret/test.pdf'
198
- expect(last_response.headers["Content-Type"]).to eq("text/html")
198
+ expect(last_response.headers["content-type"]).to eq("text/html")
199
199
  expect(last_response.body).to eq("Hello world!")
200
200
  end
201
201
  end
@@ -207,7 +207,7 @@ describe PDFKit::Middleware do
207
207
  context "matching" do
208
208
  specify do
209
209
  get 'http://www.example.org/public/test.pdf'
210
- expect(last_response.headers["Content-Type"]).to eq("application/pdf")
210
+ expect(last_response.headers["content-type"]).to eq("application/pdf")
211
211
  expect(last_response.body.bytesize).to eq(PDFKit.new("Hello world!").to_pdf.bytesize)
212
212
  end
213
213
  end
@@ -215,7 +215,7 @@ describe PDFKit::Middleware do
215
215
  context "not matching" do
216
216
  specify do
217
217
  get 'http://www.example.org/secret/test.pdf'
218
- expect(last_response.headers["Content-Type"]).to eq("text/html")
218
+ expect(last_response.headers["content-type"]).to eq("text/html")
219
219
  expect(last_response.body).to eq("Hello world!")
220
220
  end
221
221
  end
@@ -229,7 +229,7 @@ describe PDFKit::Middleware do
229
229
  context "matching" do
230
230
  specify do
231
231
  get 'http://www.example.org/public/test.pdf'
232
- expect(last_response.headers["Content-Type"]).to eq("application/pdf")
232
+ expect(last_response.headers["content-type"]).to eq("application/pdf")
233
233
  expect(last_response.body.bytesize).to eq(PDFKit.new("Hello world!").to_pdf.bytesize)
234
234
  end
235
235
  end
@@ -237,7 +237,7 @@ describe PDFKit::Middleware do
237
237
  context "not matching" do
238
238
  specify do
239
239
  get 'http://www.example.org/secret/test.pdf'
240
- expect(last_response.headers["Content-Type"]).to eq("text/html")
240
+ expect(last_response.headers["content-type"]).to eq("text/html")
241
241
  expect(last_response.body).to eq("Hello world!")
242
242
  end
243
243
  end
@@ -249,7 +249,7 @@ describe PDFKit::Middleware do
249
249
  context "matching" do
250
250
  specify do
251
251
  get 'http://www.example.org/public/test.pdf'
252
- expect(last_response.headers["Content-Type"]).to eq("application/pdf")
252
+ expect(last_response.headers["content-type"]).to eq("application/pdf")
253
253
  expect(last_response.body.bytesize).to eq(PDFKit.new("Hello world!").to_pdf.bytesize)
254
254
  end
255
255
  end
@@ -257,7 +257,7 @@ describe PDFKit::Middleware do
257
257
  context "not matching" do
258
258
  specify do
259
259
  get 'http://www.example.org/secret/test.pdf'
260
- expect(last_response.headers["Content-Type"]).to eq("text/html")
260
+ expect(last_response.headers["content-type"]).to eq("text/html")
261
261
  expect(last_response.body).to eq("Hello world!")
262
262
  end
263
263
  end
@@ -348,14 +348,14 @@ describe PDFKit::Middleware do
348
348
  describe "doesn't overwrite existing value" do
349
349
  let(:headers) do
350
350
  super().merge({
351
- 'Content-Disposition' => 'attachment; filename=report-20200101.pdf'
351
+ 'content-disposition' => 'attachment; filename=report-20200101.pdf'
352
352
  })
353
353
  end
354
354
 
355
355
  specify do
356
356
  mock_app({}, { :disposition => 'inline' })
357
357
  get 'http://www.example.org/public/test.pdf'
358
- 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')
359
359
  end
360
360
  end
361
361
 
@@ -364,7 +364,7 @@ describe PDFKit::Middleware do
364
364
  specify do
365
365
  mock_app
366
366
  get 'http://www.example.org/public/test.pdf'
367
- expect(last_response.headers["Content-Disposition"]).to eq("inline")
367
+ expect(last_response.headers["content-disposition"]).to eq("inline")
368
368
  end
369
369
  end
370
370
 
@@ -372,7 +372,7 @@ describe PDFKit::Middleware do
372
372
  specify do
373
373
  mock_app({}, { :disposition => 'inline' })
374
374
  get 'http://www.example.org/public/test.pdf'
375
- expect(last_response.headers["Content-Disposition"]).to eq("inline")
375
+ expect(last_response.headers["content-disposition"]).to eq("inline")
376
376
  end
377
377
  end
378
378
  end
@@ -382,7 +382,7 @@ describe PDFKit::Middleware do
382
382
  specify do
383
383
  mock_app({}, { :disposition => 'attachment' })
384
384
  get 'http://www.example.org/public/test.pdf'
385
- expect(last_response.headers["Content-Disposition"]).to eq("attachment")
385
+ expect(last_response.headers["content-disposition"]).to eq("attachment")
386
386
  end
387
387
  end
388
388
 
@@ -390,7 +390,7 @@ describe PDFKit::Middleware do
390
390
  specify do
391
391
  mock_app({}, { :disposition => 'attachment; filename=report.pdf' })
392
392
  get 'http://www.example.org/public/test.pdf'
393
- 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")
394
394
  end
395
395
  end
396
396
  end
@@ -446,7 +446,7 @@ describe PDFKit::Middleware do
446
446
  main_app = lambda { |env|
447
447
  @env = env
448
448
  @env['SCRIPT_NAME'] = '/example.org'
449
- headers = {'Content-Type' => "text/html"}
449
+ headers = {'content-type' => "text/html"}
450
450
  [200, headers, @body || ['Hello world!']]
451
451
  }
452
452
 
data/spec/source_spec.rb CHANGED
@@ -80,6 +80,11 @@ describe PDFKit::Source do
80
80
  expect(source.to_input_for_command).to eq "\"https://www.google.com/search?q='cat%3Cdev/zero%3E/dev/null'\""
81
81
  end
82
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
+
83
88
  it "does not URI escape previously escaped source URLs" do
84
89
  source = PDFKit::Source.new("https://www.google.com/search?q='cat%3Cdev/zero%3E/dev/null'")
85
90
  expect(source.to_input_for_command).to eq "\"https://www.google.com/search?q='cat%3Cdev/zero%3E/dev/null'\""
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.6
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: 2022-04-11 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
@@ -141,7 +141,7 @@ homepage: https://github.com/pdfkit/pdfkit
141
141
  licenses:
142
142
  - MIT
143
143
  metadata: {}
144
- post_install_message:
144
+ post_install_message:
145
145
  rdoc_options: []
146
146
  require_paths:
147
147
  - lib
@@ -158,7 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
158
158
  requirements:
159
159
  - wkhtmltopdf
160
160
  rubygems_version: 3.0.3.1
161
- signing_key:
161
+ signing_key:
162
162
  specification_version: 4
163
163
  summary: HTML+CSS -> PDF
164
164
  test_files: