diff --git a/wkhtmltopdf/tests/tests.py b/wkhtmltopdf/tests/tests.py index c9f2187..ad0f7cd 100644 --- a/wkhtmltopdf/tests/tests.py +++ b/wkhtmltopdf/tests/tests.py @@ -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""" diff --git a/wkhtmltopdf/utils.py b/wkhtmltopdf/utils.py index 68034b8..2ff4548 100644 --- a/wkhtmltopdf/utils.py +++ b/wkhtmltopdf/utils.py @@ -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): @@ -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