From 312185455361d3d2b958845cce84507903b954f6 Mon Sep 17 00:00:00 2001 From: Tobias Date: Mon, 20 Jun 2022 10:45:24 +0200 Subject: [PATCH] add support for --allow option --- README.md | 1 + lib/wicked_pdf/option_parser.rb | 3 ++- test/unit/wicked_pdf_option_parser_test.rb | 7 ++++++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 71087d47..b2e794db 100644 --- a/README.md +++ b/README.md @@ -191,6 +191,7 @@ class ThingsController < ApplicationController # define as true the key 'disable_local_file_access' or 'enable_local_file_access', not both disable_local_file_access: true, enable_local_file_access: false, # must be true when using wkhtmltopdf > 0.12.6 + allow: ["#{Rails.root}/public"], # could be an array or a single string disable_smart_shrinking: true, use_xserver: true, diff --git a/lib/wicked_pdf/option_parser.rb b/lib/wicked_pdf/option_parser.rb index add9f070..e1d3a875 100644 --- a/lib/wicked_pdf/option_parser.rb +++ b/lib/wicked_pdf/option_parser.rb @@ -168,7 +168,8 @@ def parse_others(options) encoding user_style_sheet viewport_size - window_status]) + window_status + allow]) r += make_options(options, %i[cookie post], '', :name_value) r += make_options(options, %i[redirect_delay diff --git a/test/unit/wicked_pdf_option_parser_test.rb b/test/unit/wicked_pdf_option_parser_test.rb index 3eca8220..eb4d27ae 100644 --- a/test/unit/wicked_pdf_option_parser_test.rb +++ b/test/unit/wicked_pdf_option_parser_test.rb @@ -76,6 +76,11 @@ class WickedPdfOptionParserTest < ActiveSupport::TestCase assert_equal "--#{o.to_s.tr('_', '-')} opts", parse_options(o => 'opts').strip end + %i[allow].each do |o| + assert_equal "--#{o.to_s.tr('_', '-')} opts", parse_options(o => 'opts').strip + assert_equal "--#{o.to_s.tr('_', '-')} opts1 --#{o.to_s.tr('_', '-')} opts2", parse_options(o => %w[opts1 opts2]).strip + end + %i[cookie post].each do |o| assert_equal "--#{o.to_s.tr('_', '-')} name value", parse_options(o => 'name value').strip @@ -90,7 +95,7 @@ class WickedPdfOptionParserTest < ActiveSupport::TestCase %i[ book default_header disable_javascript grayscale lowquality enable_plugins disable_internal_links disable_external_links - print_media_type disable_smart_shrinking use_xserver no_background + print_media_type disable_smart_shrinking use_xserver no_background disable_local_file_access ].each do |o| assert_equal "--#{o.to_s.tr('_', '-')}", parse_options(o => true).strip end