Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Options with multiple values get split to send to subprocess #204

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions wkhtmltopdf/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ def test_options_to_args(self):
file_name='file-name'),
['--file-name', 'file-name',
'--heart', u'♥'])
self.assertEqual(_options_to_args(
custom_header='Authentication mytoken',
cookie='key1 value1'),
['--cookie', 'key1', 'value1',
'--custom-header', 'Authentication', 'mytoken'])
with self.assertRaises(ValueError):
_options_to_args(custom_header='Authentication')

def test_wkhtmltopdf(self):
"""Should run wkhtmltopdf to generate a PDF"""
Expand Down
9 changes: 8 additions & 1 deletion wkhtmltopdf/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
'--enable-toc-back-links', '--footer-line', '--no-footer-line',
'--header-line', '--no-header-line', '--disable-dotted-lines',
'--disable-toc-links', '--verbose']
MULTI_VALUE_OPTIONS = ['--custom-header', '--cookie', '--post', '--replace']


def _options_to_args(**options):
Expand All @@ -60,12 +61,18 @@ def _options_to_args(**options):
formatted_flag = '--%s' % name if len(name) > 1 else '-%s' % name
formatted_flag = formatted_flag.replace('_', '-')
accepts_no_arguments = formatted_flag in NO_ARGUMENT_OPTIONS
is_multi_value_option = formatted_flag in MULTI_VALUE_OPTIONS
if value is None or (value is False and accepts_no_arguments):
continue
flags.append(formatted_flag)
if accepts_no_arguments:
continue
flags.append(six.text_type(value))
if is_multi_value_option:
k, v = value.split(maxsplit=1)
flags.append(six.text_type(k))
flags.append(six.text_type(v))
else:
flags.append(six.text_type(value))
return flags


Expand Down