pdfkit 0.8.6 → 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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/README.md +2 -2
- data/lib/pdfkit/middleware.rb +7 -6
- data/lib/pdfkit/source.rb +1 -1
- data/lib/pdfkit/version.rb +1 -1
- data/spec/middleware_spec.rb +58 -35
- data/spec/source_spec.rb +5 -0
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dd9ab1711dcc1f5dc4c9ec2b0f5a203394cc8276291f34bd59230dd832c6b51c
|
4
|
+
data.tar.gz: 0ec141cfe484aea9ae00488c34da32573f8f84d7ae3a5a3d5c954a0d4acfbee5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8cf1754028c05b1dab1f382c91b86672a8a2808bbabbe66132fdb78501a731b1a651b5d276c0818efba1b537a685d2f55cb2a281935edf8c7b5b58c3aed1f1a
|
7
|
+
data.tar.gz: 93f26e92cc31dd7f4fdaf1d5a20c2b2c5463d66588bc465bfacbfa4aecbbbe19662b1e605c1ac69593e1974fc0d606ff92298cfdace4c55313d977b87d128fc4
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
2022-10-17
|
2
|
+
=================
|
3
|
+
* Bump to 0.8.7.1
|
4
|
+
* Support non-lower-case Content-Type header provided by app (#516)
|
5
|
+
|
6
|
+
2022-10-02
|
7
|
+
=================
|
8
|
+
* Bump to 0.8.7
|
9
|
+
* Lowercase the header names for rack 3 changes (#511)
|
10
|
+
* Partially escaped URLs should be escaped (#509)
|
11
|
+
|
1
12
|
2022-04-11
|
2
13
|
=================
|
3
14
|
* 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
|
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 "
|
175
|
+
headers specify "content-type: application/pdf"
|
176
176
|
|
177
177
|
## Note on Patches/Pull Requests
|
178
178
|
|
data/lib/pdfkit/middleware.rb
CHANGED
@@ -22,7 +22,8 @@ class PDFKit
|
|
22
22
|
status, headers, response = @app.call(env)
|
23
23
|
|
24
24
|
begin
|
25
|
-
|
25
|
+
content_type_header = headers.has_key?('Content-Type') ? 'Content-Type' : 'content-type'
|
26
|
+
if rendering_pdf? && headers[content_type_header] =~ /text\/html|application\/xhtml\+xml/
|
26
27
|
body = response.respond_to?(:body) ? response.body : response.join
|
27
28
|
body = body.join if body.is_a?(Array)
|
28
29
|
|
@@ -44,13 +45,13 @@ class PDFKit
|
|
44
45
|
|
45
46
|
unless @caching
|
46
47
|
# Do not cache PDFs
|
47
|
-
headers.delete('
|
48
|
-
headers.delete('
|
48
|
+
headers.delete('etag')
|
49
|
+
headers.delete('cache-control')
|
49
50
|
end
|
50
51
|
|
51
|
-
headers['
|
52
|
-
headers[
|
53
|
-
headers['
|
52
|
+
headers['content-length'] = (body.respond_to?(:bytesize) ? body.bytesize : body.size).to_s
|
53
|
+
headers[content_type_header] = 'application/pdf'
|
54
|
+
headers['content-disposition'] ||= @conditions[:disposition] || 'inline'
|
54
55
|
end
|
55
56
|
rescue StandardError => e
|
56
57
|
status = 500
|
data/lib/pdfkit/source.rb
CHANGED
data/lib/pdfkit/version.rb
CHANGED
data/spec/middleware_spec.rb
CHANGED
@@ -19,7 +19,7 @@ end
|
|
19
19
|
|
20
20
|
describe PDFKit::Middleware do
|
21
21
|
let(:headers) do
|
22
|
-
{'
|
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
|
-
'
|
59
|
-
'
|
60
|
-
'
|
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
|
67
|
+
it "deletes etag" do
|
68
68
|
get 'http://www.example.org/public/test.pdf'
|
69
|
-
expect(last_response.headers["
|
69
|
+
expect(last_response.headers["etag"]).to be_nil
|
70
70
|
end
|
71
|
-
it "deletes
|
71
|
+
it "deletes cache-control" do
|
72
72
|
get 'http://www.example.org/public/test.pdf'
|
73
|
-
expect(last_response.headers["
|
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
|
80
|
+
it "preserves etag" do
|
81
81
|
get 'http://www.example.org/public/test.pdf'
|
82
|
-
expect(last_response.headers["
|
82
|
+
expect(last_response.headers["etag"]).not_to be_nil
|
83
83
|
end
|
84
84
|
|
85
|
-
it "preserves
|
85
|
+
it "preserves cache-control" do
|
86
86
|
get 'http://www.example.org/public/test.pdf'
|
87
|
-
expect(last_response.headers["
|
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["
|
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["
|
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["
|
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["
|
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["
|
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["
|
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["
|
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["
|
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["
|
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["
|
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["
|
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["
|
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["
|
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["
|
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["
|
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["
|
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
|
-
'
|
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["
|
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["
|
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["
|
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["
|
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["
|
393
|
+
expect(last_response.headers["content-disposition"]).to eq("attachment; filename=report.pdf")
|
394
394
|
end
|
395
395
|
end
|
396
396
|
end
|
@@ -422,6 +422,29 @@ describe PDFKit::Middleware do
|
|
422
422
|
end
|
423
423
|
end
|
424
424
|
|
425
|
+
describe "content type header" do
|
426
|
+
before { mock_app }
|
427
|
+
|
428
|
+
context "lower case" do
|
429
|
+
specify "header gets correctly updated" do
|
430
|
+
get 'http://www.example.org/public/test.pdf'
|
431
|
+
expect(last_response.headers["content-type"]).to eq("application/pdf")
|
432
|
+
end
|
433
|
+
end
|
434
|
+
|
435
|
+
context "mixed case" do
|
436
|
+
let(:headers) do
|
437
|
+
{'Content-Type' => "text/html"}
|
438
|
+
end
|
439
|
+
|
440
|
+
specify "header gets correctly updated" do
|
441
|
+
pending("this test only applies to rack 2.x and is rejected by rack 3.x") if Rack.release >= "3.0.0"
|
442
|
+
get 'http://www.example.org/public/test.pdf'
|
443
|
+
expect(last_response.headers["Content-Type"]).to eq("application/pdf")
|
444
|
+
end
|
445
|
+
end
|
446
|
+
end
|
447
|
+
|
425
448
|
describe "remove .pdf from PATH_INFO and REQUEST_URI" do
|
426
449
|
before { mock_app }
|
427
450
|
|
@@ -446,7 +469,7 @@ describe PDFKit::Middleware do
|
|
446
469
|
main_app = lambda { |env|
|
447
470
|
@env = env
|
448
471
|
@env['SCRIPT_NAME'] = '/example.org'
|
449
|
-
headers = {'
|
472
|
+
headers = {'content-type' => "text/html"}
|
450
473
|
[200, headers, @body || ['Hello world!']]
|
451
474
|
}
|
452
475
|
|
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.
|
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: 2022-
|
12
|
+
date: 2022-10-17 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:
|