wicked_pdf 2.1.0 → 2.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2a1ed5bc6831790ca7a345a234788f25c80fa9cf9ce29cd6059c4f3e2b95899b
4
- data.tar.gz: 8403943792fa00a8d6103227d9c64d1235d7bc15fd1c1dc0b1c5b781595d1129
3
+ metadata.gz: cbaa0b111a2d8d8e2f0bb2264d07be067f117c599ffb970bb928105d7fb19987
4
+ data.tar.gz: b53d91e583bbf63e9a5b3d6680f469af46532a2dd0ff08530f2bf33d070043f5
5
5
  SHA512:
6
- metadata.gz: 91ff0d2567e0aff820cc482da2c76df3823fdb3be007229236907c0d4f8e2caf50a14e18f49a52f18d748f23f1c71f9010002417726c319a9064158cddd66ccd
7
- data.tar.gz: 259d606917744373d121f6c4c1a84fa80411b326f92f45c049ad5cd4950adb4121befd0b7f765400594fed8b292670b0f32b8916632b1dc5727524877e046e0c
6
+ metadata.gz: 1400fde655ba636ac73cac318903f8b9f0dc69709034cd61e90f17f70bab8ee18d39c4c19d09fc95050ff91e99da204b09d8fb33b69169389e5b5064be04b306
7
+ data.tar.gz: 74ea968b08bfd3de6f7814e86abdb269bdf35110f50ea232b5e1bb224b2a2274fef31f7ac51e2db66b3734c218dff3bb38e013023fd08cfcc7f6c869201b9e9c
@@ -0,0 +1,56 @@
1
+ name: CI
2
+
3
+ on: [push, pull_request, workflow_dispatch]
4
+
5
+ jobs:
6
+ tests:
7
+ name: Tests with Ruby ${{ matrix.ruby-version }} and Rails ${{ matrix.gemfile }}
8
+ runs-on: ubuntu-latest
9
+ strategy:
10
+ matrix:
11
+ gemfile: ["5.0"]
12
+ ruby-version: [2.6]
13
+ include:
14
+ - gemfile: "5.0"
15
+ ruby-version: 2.7
16
+ - gemfile: "5.1"
17
+ ruby-version: 2.6
18
+ - gemfile: "5.1"
19
+ ruby-version: 2.7
20
+ - gemfile: "5.2"
21
+ ruby-version: 2.6
22
+ - gemfile: "5.2"
23
+ ruby-version: 2.7
24
+ - gemfile: "6.0"
25
+ ruby-version: 2.6
26
+ - gemfile: "6.0"
27
+ ruby-version: 2.7
28
+ - gemfile: "6.1"
29
+ ruby-version: 2.7
30
+ - gemfile: "6.1"
31
+ ruby-version: 3.0
32
+ - gemfile: "7.0"
33
+ ruby-version: 3.0
34
+
35
+ env:
36
+ BUNDLE_GEMFILE: /home/runner/work/wicked_pdf/wicked_pdf/gemfiles/${{ matrix.gemfile }}.gemfile
37
+ WKHTMLTOPDF_BIN: /usr/bin/wkhtmltopdf
38
+
39
+ steps:
40
+ - uses: actions/checkout@v2
41
+
42
+ - name: Install Ruby ${{ matrix.ruby-version }}
43
+ uses: ruby/setup-ruby@v1
44
+ with:
45
+ ruby-version: ${{ matrix.ruby-version }}
46
+
47
+ - name: Install OS dependencies
48
+ run: |
49
+ sudo apt-get update -y -qq
50
+ sudo apt-get install -y wkhtmltopdf
51
+
52
+ - name: Install gem dependencies
53
+ run: bundle install
54
+
55
+ - name: Run tests with Ruby ${{ matrix.ruby-version }} and Rails ${{ matrix.gemfile }}
56
+ run: bundle exec rake
data/.rubocop.yml CHANGED
@@ -1,11 +1,60 @@
1
1
  inherit_from: .rubocop_todo.yml
2
2
 
3
3
  AllCops:
4
- TargetRubyVersion: 2.2
4
+ NewCops: disable
5
+ TargetRubyVersion: 2.6
5
6
  Exclude:
6
7
  - 'gemfiles/bin/*'
7
8
  - 'test/dummy/**/*'
8
9
 
10
+ Metrics/PerceivedComplexity:
11
+ Enabled: false
12
+
13
+ Gemspec/RequiredRubyVersion:
14
+ Enabled: false
15
+
16
+ Bundler/OrderedGems:
17
+ Enabled: false
18
+
19
+ Style/FrozenStringLiteralComment:
20
+ Enabled: false
21
+
22
+ Style/RedundantBegin:
23
+ Enabled: false
24
+
25
+ Style/NumericPredicate:
26
+ Enabled: false
27
+
28
+ Style/RedundantRegexpEscape:
29
+ Enabled: false
30
+
31
+ Style/SafeNavigation:
32
+ Enabled: false
33
+
34
+ Lint/SendWithMixinArgument:
35
+ Enabled: false
36
+
37
+ Lint/RedundantCopDisableDirective:
38
+ Enabled: false
39
+
40
+ Metrics/AbcSize:
41
+ Enabled: false
42
+
43
+ Style/StringConcatenation:
44
+ Enabled: false
45
+
46
+ Style/RedundantFetchBlock:
47
+ Enabled: false
48
+
49
+ Style/CaseLikeIf:
50
+ Enabled: false
51
+
52
+ Style/SoleNestedConditional:
53
+ Enabled: false
54
+
55
+ Style/RedundantReturn:
56
+ Enabled: false
57
+
9
58
  Metrics/BlockLength:
10
59
  Exclude:
11
60
  - 'wicked_pdf.gemspec'
data/.rubocop_todo.yml CHANGED
@@ -1,64 +1,11 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2019-10-02 17:54:14 +0200 using RuboCop version 0.68.1.
3
+ # on 2019-10-09 14:16:04 +0200 using RuboCop version 0.68.1.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
7
7
  # versions of RuboCop, may require this file to be generated again.
8
8
 
9
- # Offense count: 9
10
- # Cop supports --auto-correct.
11
- # Configuration parameters: TreatCommentsAsGroupSeparators, Include.
12
- # Include: **/*.gemfile, **/Gemfile, **/gems.rb
13
- Bundler/OrderedGems:
14
- Exclude:
15
- - 'gemfiles/4.0.gemfile'
16
- - 'gemfiles/4.1.gemfile'
17
- - 'gemfiles/4.2.gemfile'
18
- - 'gemfiles/5.0.gemfile'
19
- - 'gemfiles/5.1.gemfile'
20
- - 'gemfiles/5.2.gemfile'
21
- - 'gemfiles/6.0.gemfile'
22
- - 'gemfiles/rails_edge.gemfile'
23
-
24
- # Offense count: 2
25
- # Cop supports --auto-correct.
26
- # Configuration parameters: TreatCommentsAsGroupSeparators, Include.
27
- # Include: **/*.gemspec
28
- Gemspec/OrderedDependencies:
29
- Exclude:
30
- - 'wicked_pdf.gemspec'
31
-
32
- # Offense count: 16
33
- # Cop supports --auto-correct.
34
- Layout/EmptyLineAfterGuardClause:
35
- Exclude:
36
- - 'Rakefile'
37
- - 'lib/wicked_pdf.rb'
38
- - 'lib/wicked_pdf/pdf_helper.rb'
39
- - 'lib/wicked_pdf/wicked_pdf_helper/assets.rb'
40
-
41
- # Offense count: 2
42
- # Cop supports --auto-correct.
43
- Layout/LeadingBlankLines:
44
- Exclude:
45
- - 'test/unit/wkhtmltopdf_location_test.rb'
46
- - 'wicked_pdf.gemspec'
47
-
48
- # Offense count: 1
49
- # Cop supports --auto-correct.
50
- Layout/RescueEnsureAlignment:
51
- Exclude:
52
- - 'lib/wicked_pdf.rb'
53
-
54
- # Offense count: 1
55
- # Cop supports --auto-correct.
56
- # Configuration parameters: EnforcedStyle.
57
- # SupportedStyles: final_newline, final_blank_line
58
- Layout/TrailingBlankLines:
59
- Exclude:
60
- - 'gemfiles/4.0.gemfile'
61
-
62
9
  # Offense count: 11
63
10
  Metrics/AbcSize:
64
11
  Max: 45
@@ -66,16 +13,16 @@ Metrics/AbcSize:
66
13
  # Offense count: 2
67
14
  # Configuration parameters: CountComments.
68
15
  Metrics/ClassLength:
69
- Max: 292
16
+ Max: 250
70
17
 
71
18
  # Offense count: 7
72
19
  Metrics/CyclomaticComplexity:
73
- Max: 11
20
+ Max: 13
74
21
 
75
22
  # Offense count: 17
76
23
  # Configuration parameters: CountComments, ExcludedMethods.
77
24
  Metrics/MethodLength:
78
- Max: 30
25
+ Max: 40
79
26
 
80
27
  # Offense count: 2
81
28
  # Configuration parameters: CountComments.
@@ -84,7 +31,7 @@ Metrics/ModuleLength:
84
31
 
85
32
  # Offense count: 6
86
33
  Metrics/PerceivedComplexity:
87
- Max: 12
34
+ Max: 13
88
35
 
89
36
  # Offense count: 2
90
37
  Naming/AccessorMethodName:
@@ -92,11 +39,6 @@ Naming/AccessorMethodName:
92
39
  - 'lib/wicked_pdf/middleware.rb'
93
40
  - 'lib/wicked_pdf/pdf_helper.rb'
94
41
 
95
- # Offense count: 1
96
- Security/Open:
97
- Exclude:
98
- - 'lib/wicked_pdf/wicked_pdf_helper/assets.rb'
99
-
100
42
  # Offense count: 1
101
43
  Style/CaseEquality:
102
44
  Exclude:
@@ -118,6 +60,8 @@ Style/Documentation:
118
60
  - 'lib/wicked_pdf/pdf_helper.rb'
119
61
  - 'lib/wicked_pdf/progress.rb'
120
62
  - 'lib/wicked_pdf/railtie.rb'
63
+ - 'lib/wicked_pdf/binary.rb'
64
+ - 'lib/wicked_pdf/option_parser.rb'
121
65
  - 'lib/wicked_pdf/tempfile.rb'
122
66
  - 'lib/wicked_pdf/wicked_pdf_helper.rb'
123
67
  - 'lib/wicked_pdf/wicked_pdf_helper/assets.rb'
@@ -144,14 +88,6 @@ Style/HashSyntax:
144
88
  - 'gemfiles/6.0.gemfile'
145
89
  - 'gemfiles/rails_edge.gemfile'
146
90
 
147
- # Offense count: 3
148
- # Cop supports --auto-correct.
149
- Style/IfUnlessModifier:
150
- Exclude:
151
- - 'Rakefile'
152
- - 'lib/wicked_pdf.rb'
153
- - 'lib/wicked_pdf/railtie.rb'
154
-
155
91
  # Offense count: 2
156
92
  # Cop supports --auto-correct.
157
93
  # Configuration parameters: EnforcedStyle.
@@ -170,21 +106,6 @@ Style/RegexpLiteral:
170
106
  - 'lib/wicked_pdf/wicked_pdf_helper/assets.rb'
171
107
  - 'test/unit/wicked_pdf_test.rb'
172
108
 
173
- # Offense count: 1
174
- # Cop supports --auto-correct.
175
- # Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
176
- # SupportedStyles: single_quotes, double_quotes
177
- Style/StringLiterals:
178
- Exclude:
179
- - 'gemfiles/4.0.gemfile'
180
-
181
- # Offense count: 29
182
- # Cop supports --auto-correct.
183
- # Configuration parameters: MinSize.
184
- # SupportedStyles: percent, brackets
185
- Style/SymbolArray:
186
- EnforcedStyle: brackets
187
-
188
109
  # Offense count: 111
189
110
  # Cop supports --auto-correct.
190
111
  # Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
data/CHANGELOG.md CHANGED
@@ -4,11 +4,62 @@ This project adheres to [Semantic Versioning](http://semver.org/).
4
4
 
5
5
  ## [master branch] - Unreleased
6
6
  ### Breaking Changes
7
- - None
7
+
8
+ ## [2.6.0]
8
9
  ### New Features
9
- - None
10
+ - [Support Propshaft in find_asset helper](https://github.com/mileszs/wicked_pdf/pull/1010)
10
11
  ### Fixes
11
- - None
12
+ - [Update Changelog with changes from 2.1.0](https://github.com/mileszs/wicked_pdf/pull/1013)
13
+ - [Fix CI build for Rails 7.](https://github.com/mileszs/wicked_pdf/pull/1014)
14
+
15
+ ## [2.5.4] December 20th 2021 769f9df487f3c1e31dc91431666baa78d2aa24fb
16
+ ### New Features
17
+ - [Test with Rails 7](https://github.com/mileszs/wicked_pdf/pull/998)
18
+ ### Fixes
19
+ - [Include view helper on view load.](https://github.com/mileszs/wicked_pdf/pull/992)
20
+
21
+ ## [2.5.3] December 15th 2021 7991877de634067b4245fb47fdad65da43761887
22
+ - [Fix check for webpacker version](https://github.com/mileszs/wicked_pdf/pull/964)
23
+ - [Complete transition to Github actions](https://github.com/mileszs/wicked_pdf/pull/987)
24
+
25
+ ## [2.5.2] November 2021 - fix webpacker_source_url bdd0ca3eca759e277ce5461141b1506f56fefcd1
26
+ - [fix: `webpacker_source_url`](https://github.com/mileszs/wicked_pdf/pull/993)
27
+ - [update README](https://github.com/mileszs/wicked_pdf/pull/968)
28
+
29
+ ## [2.5.1] September 2021 - fix webpacker helper, github actions and Readme updates ae725e8055dc8f51a392c27767b4dcdcfffe155d
30
+ - [Add comment about enable_local_file_access to README](https://github.com/mileszs/wicked_pdf/commit/2dc96dde2e0fd7362395064f2480cac1edcc1f48)
31
+ - [README updates](https://github.com/mileszs/wicked_pdf/pull/974) &&
32
+ - [Github actions](https://github.com/mileszs/wicked_pdf/pull/986)
33
+ - [Screencast links](https://github.com/mileszs/wicked_pdf/pull/976)
34
+ - [fix url generating in webpacker helper](https://github.com/mileszs/wicked_pdf/pull/973)
35
+
36
+ ## [2.5.0] November 2020 Release - 2b1d47a84fce3600e7cbe2f50843af1a7b84d4a6
37
+ - [Remove code for unsupported rails and ruby versions](https://github.com/mileszs/wicked_pdf/pull/925)
38
+
39
+ ## [2.4.1] b56c46a05895def395ebc75ed8e822551c2c478f
40
+ - [Extract reading in chunk](https://github.com/mileszs/wicked_pdf/pull/951)
41
+ - [add ruby 2.7 to the test matrix](https://github.com/mileszs/wicked_pdf/pull/952)
42
+
43
+ ## [2.4.0] 8c007a77057e1a6680469d1ef53aa19a108fe209
44
+ ### New Features
45
+ - [Do not unlink HTML temp files immediately (to enable HTML tempfile inspection)](https://github.com/mileszs/wicked_pdf/pull/950)
46
+ - [Read HTML string and generated PDF file in chunks (to reduce memory overhead of generating large PDFs)](https://github.com/mileszs/wicked_pdf/pull/949)
47
+ - [Add `wicked_pdf_url_base64` helper](https://github.com/mileszs/wicked_pdf/pull/947)
48
+
49
+ ## [2.3.1] - Allow bundler 2.x ee6a5e1f807c872af37c1382f629dd4cac3040a8
50
+ - [Adjust gemspec development dependencies](https://github.com/mileszs/wicked_pdf/pull/814)
51
+
52
+ ## [2.3.0] - Remove support for Ruby 1.x and Rails 2.x 66149c67e54cd3a63dd27528f5b78255fdd5ac43
53
+ - [Remove support for Ruby 1.x and Rails 2.x](https://github.com/mileszs/wicked_pdf/pull/859)
54
+
55
+ ## [2.2.0] - October 2020 release f8abe706f5eb6dba2fcded473c81f2176e9d717e
56
+ ### Fixes
57
+ - [Make CI green again](https://github.com/mileszs/wicked_pdf/pull/939)
58
+ - [rubocop fixes](https://github.com/mileszs/wicked_pdf/pull/945)
59
+ ### New Features
60
+ - [Add support for --keep-relative-links flag](https://github.com/mileszs/wicked_pdf/pull/930)
61
+ - [Encapsulate binary path and version handling](https://github.com/mileszs/wicked_pdf/pull/816) && [#815](https://github.com/mileszs/wicked_pdf/pull/815)
62
+
12
63
 
13
64
  ## [2.1.0] - 2020-06-14
14
65
  ### Fixes
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Wicked PDF [![Gem Version](https://badge.fury.io/rb/wicked_pdf.svg)](http://badge.fury.io/rb/wicked_pdf) [![Build Status](https://secure.travis-ci.org/mileszs/wicked_pdf.svg)](http://travis-ci.org/mileszs/wicked_pdf) [![Code Climate](https://codeclimate.com/github/mileszs/wicked_pdf/badges/gpa.svg)](https://codeclimate.com/github/mileszs/wicked_pdf) [![Open Source Helpers](https://www.codetriage.com/mileszs/wicked_pdf/badges/users.svg)](https://www.codetriage.com/mileszs/wicked_pdf)
1
+ # Wicked PDF [![Gem Version](https://badge.fury.io/rb/wicked_pdf.svg)](http://badge.fury.io/rb/wicked_pdf) [![Build Status](https://github.com/mileszs/wicked_pdf/actions/workflows/ci.yml/badge.svg)](https://github.com/mileszs/wicked_pdf/actions/workflows/ci.yml) [![Code Climate](https://codeclimate.com/github/mileszs/wicked_pdf/badges/gpa.svg)](https://codeclimate.com/github/mileszs/wicked_pdf) [![Open Source Helpers](https://www.codetriage.com/mileszs/wicked_pdf/badges/users.svg)](https://www.codetriage.com/mileszs/wicked_pdf)
2
2
 
3
3
  ## A PDF generation plugin for Ruby on Rails
4
4
 
@@ -43,7 +43,8 @@ If your wkhtmltopdf executable is not on your webserver's path, you can configur
43
43
 
44
44
  ```ruby
45
45
  WickedPdf.config = {
46
- exe_path: '/usr/local/bin/wkhtmltopdf'
46
+ exe_path: '/usr/local/bin/wkhtmltopdf',
47
+ enable_local_file_access: true
47
48
  }
48
49
  ```
49
50
 
@@ -111,10 +112,9 @@ Using wicked_pdf_helpers with asset pipeline raises `Asset names passed to helpe
111
112
 
112
113
  wicked_pdf supports webpack assets.
113
114
 
114
- Use `wicked_pdf_stylesheet_pack_tag` for stylesheets
115
- Use `wicked_pdf_javascript_pack_tag` for javascripts
116
-
117
- Use `wicked_pdf_asset_pack_path` to access an asset directly, for example: `image_tag wicked_pdf_asset_pack_path("media/images/foobar.png")`
115
+ - Use `wicked_pdf_stylesheet_pack_tag` for stylesheets
116
+ - Use `wicked_pdf_javascript_pack_tag` for javascripts
117
+ - Use `wicked_pdf_asset_pack_path` to access an asset directly, for example: `image_tag wicked_pdf_asset_pack_path("media/images/foobar.png")`
118
118
 
119
119
  #### Asset pipeline usage
120
120
 
@@ -126,11 +126,11 @@ It is best to precompile assets used in PDF views. This will help avoid issues w
126
126
 
127
127
  In this case, you can use that standard Rails helpers and point to the current CDN for whichever framework you are using. For jQuery, it would look somethng like this, given the current versions at the time of this writing.
128
128
  ```html
129
- <!doctype html>
130
- <html>
131
- <head>
132
- <%= javascript_include_tag "http://code.jquery.com/jquery-1.10.0.min.js" %>
133
- <%= javascript_include_tag "http://code.jquery.com/ui/1.10.3/jquery-ui.min.js" %>
129
+ <!doctype html>
130
+ <html>
131
+ <head>
132
+ <%= javascript_include_tag "http://code.jquery.com/jquery-1.10.0.min.js" %>
133
+ <%= javascript_include_tag "http://code.jquery.com/ui/1.10.3/jquery-ui.min.js" %>
134
134
  ```
135
135
 
136
136
  ### Advanced Usage with all available options
@@ -185,11 +185,12 @@ class ThingsController < ApplicationController
185
185
  enable_plugins: true,
186
186
  disable_internal_links: true,
187
187
  disable_external_links: true,
188
+ keep_relative_links: true,
188
189
  print_media_type: true,
189
190
 
190
191
  # define as true the key 'disable_local_file_access' or 'enable_local_file_access', not both
191
192
  disable_local_file_access: true,
192
- enable_local_file_access: false,
193
+ enable_local_file_access: false, # must be true when using wkhtmltopdf > 0.12.6
193
194
 
194
195
  disable_smart_shrinking: true,
195
196
  use_xserver: true,
@@ -430,8 +431,22 @@ JESii's post [WickedPDF, wkhtmltopdf, and Heroku...a tricky combination](http://
430
431
 
431
432
  Berislav Babic's post [Send PDF attachments from Rails with WickedPdf and ActionMailer](http://berislavbabic.com/send-pdf-attachments-from-rails-with-wickedpdf-and-actionmailer/)
432
433
 
434
+ Corsego's 2021 post [Complete guide to generating PDFs with gem wicked_pdf](https://blog.corsego.com/gem-wicked-pdf)
435
+
436
+ PDFTron's post [How to Generate PDFs With Ruby on Rails](https://www.pdftron.com/blog/rails/how-to-generate-pdf-with-ruby-on-rails/)
437
+
433
438
  StackOverflow [questions with the tag "wicked-pdf"](http://stackoverflow.com/questions/tagged/wicked-pdf)
434
439
 
440
+ ### Screencasts
441
+
442
+ * SupeRails Screencast [EN]
443
+
444
+ [![Ruby on Rails #17 generate, save, send PDFs with gem wicked_pdf](https://i3.ytimg.com/vi/tFvtwEmW-GE/hqdefault.jpg)](https://youtu.be/tFvtwEmW-GE)
445
+
446
+ * codigofacilito Screencast [ES]
447
+
448
+ [![Generar PDF con Ruby on Rails - Tutorial](https://i3.ytimg.com/vi/jeWM_gusmJc/hqdefault.jpg)](https://youtu.be/jeWM_gusmJc)
449
+
435
450
  ### Debugging
436
451
 
437
452
  Now you can use a debug param on the URL that shows you the content of the pdf in plain html to design it faster.
@@ -442,7 +457,7 @@ http://localhost:3001/CONTROLLER/X.pdf?debug
442
457
 
443
458
  However, the wicked_pdf_* helpers will use file:/// paths for assets when using :show_as_html, and your browser's cross-domain safety feature will kick in, and not render them. To get around this, you can load your assets like so in your templates:
444
459
  ```html
445
- <%= params.key?('debug') ? image_tag('foo') : wicked_pdf_image_tag('foo') %>
460
+ <%= params.key?('debug') ? image_tag('foo') : wicked_pdf_image_tag('foo') %>
446
461
  ```
447
462
 
448
463
  #### Gotchas
@@ -451,6 +466,22 @@ If one image from your HTML cannot be found (relative or wrong path for example)
451
466
 
452
467
  wkhtmltopdf may render at different resolutions on different platforms. For example, Linux prints at 75 dpi (native for WebKit) while on Windows it's at the desktop's DPI (which is normally 96 dpi). [Use `:zoom => 0.78125`](https://github.com/wkhtmltopdf/wkhtmltopdf/issues/2184) (75/96) to match Linux rendering to Windows.
453
468
 
469
+ ### Security considerations
470
+
471
+ WickedPdf renders page content on the server by saving HTML and assets to temporary files on disk, then executing `wkhtmltopdf` to convert that HTML to a PDF file.
472
+
473
+ It is highly recommended if you allow user-generated HTML/CSS/JS to be converted to PDF, you sanitize it first, or at least disallow requesting content from internal IP addresses and hostnames.
474
+
475
+ For example, these could potentially leak internal AWS metadata:
476
+ ```html
477
+ <iframe src="http://169.254.169.254/latest/meta-data/"></iframe>
478
+ <object data="http://169.254.169.254/latest/meta-data/" type="text/html">
479
+ ```
480
+
481
+ Thank you to Adam Gold from [Snyk](https://snyk.io) for reporting this.
482
+ We are considering adding host allow & block lists and/or potentially HTML element sanitizing.
483
+ Please open an issue or PR to help us out with this.
484
+
454
485
  ### Inspiration
455
486
 
456
487
  You may have noticed: this plugin is heavily inspired by the PrinceXML plugin [princely](http://github.com/mbleigh/princely/tree/master). PrinceXML's cost was prohibitive for me. So, with a little help from some friends (thanks [jqr](http://github.com/jqr)), I tracked down wkhtmltopdf, and here we are.
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ require 'rails/version'
5
5
  require 'bundler/gem_tasks'
6
6
 
7
7
  desc 'Default: run unit tests.'
8
- task :default => [:setup_and_run_tests, :rubocop]
8
+ task :default => %i[setup_and_run_tests rubocop]
9
9
 
10
10
  desc 'Test the wicked_pdf plugin.'
11
11
  Rake::TestTask.new(:test) do |t|
@@ -17,16 +17,13 @@ end
17
17
 
18
18
  desc 'Run RuboCop'
19
19
  task :rubocop do
20
- next unless RUBY_VERSION >= '2.0.0'
21
20
  require 'rubocop/rake_task'
22
21
  RuboCop::RakeTask.new
23
22
  end
24
23
 
25
24
  desc 'Setup and run all tests'
26
25
  task :setup_and_run_tests do
27
- unless File.exist?('test/dummy/config/environment.rb')
28
- Rake::Task[:dummy_generate].invoke
29
- end
26
+ Rake::Task[:dummy_generate].invoke unless File.exist?('test/dummy/config/environment.rb')
30
27
  Rake::Task[:test].invoke
31
28
  end
32
29
 
@@ -34,11 +31,7 @@ desc 'Generate dummy application for test cases'
34
31
  task :dummy_generate do
35
32
  Rake::Task[:dummy_remove].invoke
36
33
  puts 'Creating dummy application to run tests'
37
- if Rails::VERSION::MAJOR > 2
38
- system('rails new test/dummy --database=sqlite3')
39
- else
40
- system('rails test/dummy')
41
- end
34
+ system('rails new test/dummy --database=sqlite3')
42
35
  system('touch test/dummy/db/schema.rb')
43
36
  FileUtils.cp 'test/fixtures/database.yml', 'test/dummy/config/'
44
37
  FileUtils.rm_r Dir.glob('test/dummy/test/*')
data/gemfiles/5.0.gemfile CHANGED
@@ -1,8 +1,8 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ gem 'rails', '~> 5.0.0'
3
4
  gem 'rdoc'
4
- gem 'sqlite3', '~> 1.3.6'
5
5
  gem 'sprockets', '~>3.0' # v4 strips newlines from assets causing tests to fail
6
- gem 'rails', '~> 5.0.0'
6
+ gem 'sqlite3', '~> 1.3.6'
7
7
 
8
8
  gemspec path: '../'
data/gemfiles/5.1.gemfile CHANGED
@@ -1,8 +1,8 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ gem 'rails', '~> 5.1.0'
3
4
  gem 'rdoc'
4
- gem 'sqlite3', '~> 1.3.6'
5
5
  gem 'sprockets', '~>3.0' # v4 strips newlines from assets causing tests to fail
6
- gem 'rails', '~> 5.1.0'
6
+ gem 'sqlite3', '~> 1.3.6'
7
7
 
8
8
  gemspec path: '../'
data/gemfiles/5.2.gemfile CHANGED
@@ -1,10 +1,9 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'rdoc'
3
+ gem 'bootsnap' # required to run `rake test` in Rails 5.2
4
4
  gem 'rails', '~> 5.2'
5
- gem 'sqlite3', '~> 1.3.6'
5
+ gem 'rdoc'
6
6
  gem 'sprockets', '~>3.0' # v4 strips newlines from assets causing tests to fail
7
- gem 'bootsnap' # required to run `rake test` in Rails 5.2
8
- gem 'mocha', '= 1.3' # newer versions blow up
7
+ gem 'sqlite3', '~> 1.3.6'
9
8
 
10
9
  gemspec path: '../'
data/gemfiles/6.0.gemfile CHANGED
@@ -1,11 +1,10 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ gem 'bootsnap' # required to run `rake test` in Rails 6.0
3
4
  gem 'bundler', '~>2'
4
- gem 'rdoc'
5
5
  gem 'rails', '~>6.0.1'
6
- gem 'sqlite3', '~> 1.4'
6
+ gem 'rdoc'
7
7
  gem 'sprockets', '~>3.0'
8
- gem 'bootsnap' # required to run `rake test` in Rails 6.0
9
- gem 'mocha', '= 1.3' # newer versions blow up
8
+ gem 'sqlite3', '~> 1.4'
10
9
 
11
10
  gemspec path: '../'
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'bootsnap' # required to run `rake test` in Rails 6.1
4
+ gem 'bundler', '~>2'
5
+ gem 'rails', '~>6.1.0'
6
+ gem 'webpacker'
7
+ gem 'rdoc'
8
+ gem 'sprockets', '~>3.0'
9
+ gem 'sqlite3', '~> 1.4'
10
+ gem 'rubocop', '1.11.0'
11
+
12
+ gemspec :path => '../'
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'bootsnap' # required to run `rake test` in Rails 7.0
4
+ gem 'bundler', '~>2'
5
+ gem 'rails', '~>7.0.0'
6
+ gem 'sprockets-rails'
7
+ gem 'rdoc'
8
+ gem 'sprockets', '~>3.0'
9
+ gem 'sqlite3', '~> 1.4'
10
+ gem 'rubocop', '1.11.0'
11
+
12
+ gemspec :path => '../'
@@ -15,6 +15,9 @@ WickedPdf.config = {
15
15
  # or
16
16
  # exe_path: Gem.bin_path('wkhtmltopdf-binary', 'wkhtmltopdf')
17
17
 
18
+ # Needed for wkhtmltopdf 0.12.6+ to use many wicked_pdf asset helpers
19
+ # enable_local_file_access: true,
20
+
18
21
  # Layout file to be used for all PDFs
19
22
  # (but can be overridden in `render :pdf` calls)
20
23
  # layout: 'pdf.html',
@@ -0,0 +1,65 @@
1
+ class WickedPdf
2
+ class Binary
3
+ EXE_NAME = 'wkhtmltopdf'.freeze
4
+
5
+ attr_reader :path, :default_version
6
+
7
+ def initialize(binary_path, default_version = WickedPdf::DEFAULT_BINARY_VERSION)
8
+ @path = binary_path || find_binary_path
9
+ @default_version = default_version
10
+
11
+ raise "Location of #{EXE_NAME} unknown" if @path.empty?
12
+ raise "Bad #{EXE_NAME}'s path: #{@path}" unless File.exist?(@path)
13
+ raise "#{EXE_NAME} is not executable" unless File.executable?(@path)
14
+ end
15
+
16
+ def version
17
+ @version ||= retrieve_binary_version
18
+ end
19
+
20
+ def parse_version_string(version_info)
21
+ match_data = /wkhtmltopdf\s*(\d*\.\d*\.\d*\w*)/.match(version_info)
22
+ if match_data && (match_data.length == 2)
23
+ Gem::Version.new(match_data[1])
24
+ else
25
+ default_version
26
+ end
27
+ end
28
+
29
+ def xvfb_run_path
30
+ path = possible_binary_locations.map { |l| File.expand_path("#{l}/xvfb-run") }.find { |location| File.exist?(location) }
31
+ raise StandardError, 'Could not find binary xvfb-run on the system.' unless path
32
+
33
+ path
34
+ end
35
+
36
+ private
37
+
38
+ def retrieve_binary_version
39
+ _stdin, stdout, _stderr = Open3.popen3(@path + ' -V')
40
+ parse_version_string(stdout.gets(nil))
41
+ rescue StandardError
42
+ default_version
43
+ end
44
+
45
+ def find_binary_path
46
+ exe_path ||= WickedPdf.config[:exe_path] unless WickedPdf.config.empty?
47
+ exe_path ||= possible_which_path
48
+ exe_path ||= possible_locations.map { |l| File.expand_path("#{l}/#{EXE_NAME}") }.find { |location| File.exist?(location) }
49
+ exe_path || ''
50
+ end
51
+
52
+ def possible_which_path
53
+ detected_path = (defined?(Bundler) ? Bundler.which('wkhtmltopdf') : `which wkhtmltopdf`).chomp
54
+ detected_path.present? && detected_path
55
+ rescue StandardError
56
+ nil
57
+ end
58
+
59
+ def possible_binary_locations
60
+ possible_locations = (ENV['PATH'].split(':') + %w[/usr/bin /usr/local/bin]).uniq
61
+ possible_locations += %w[~/bin] if ENV.key?('HOME')
62
+ possible_locations
63
+ end
64
+ end
65
+ end