incuna / django-wkhtmltopdf

Django Wrapper to the PDF Renderer: wkhtmltopdf
BSD 2-Clause "Simplified" License
326 stars 155 forks source link

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

Open noelevans opened 1 week ago

noelevans commented 1 week ago

When an option like --custom-header Authorization my-token is received this must be broken in to 3 strings to be given to subprocess.Popen

With the previous code where "Authorization my-token" was one string, Popen does not correctly pass both arguments with --custom-header. Consequently wkhtmltopdf ignores any --custom-header instruction sent to it from django-wkhtml. The problem can be seen by running these commands:

import subprocess cmd = ['curl', '--dump-header output', 'https://api.github.com'] subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate() (b'', b"curl: option --dump-header output: is unknown\ncurl: try 'curl --help' for more information\n")

If you change the above command to be

cmd = ['curl', '--dump-header', 'output', 'https://api.github.com']

then the call works and makes a file called "output" containing header information.