From adf127b2829cc37fdf36e35c000ca558dfcd7cfb Mon Sep 17 00:00:00 2001 From: rahxam Date: Fri, 21 Jul 2017 12:30:37 +0200 Subject: [PATCH 1/2] Extends tmp file options Adds xsl-style-sheet and user-style-sheet to the regular expression, which matches options that expect an URL or a file name, so we need to create a tmp file for the content. --- src/Pdf.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Pdf.php b/src/Pdf.php index 69b5bff..03081d9 100644 --- a/src/Pdf.php +++ b/src/Pdf.php @@ -299,8 +299,8 @@ protected function processInput($input, $type=null) protected function processOptions($options=array()) { foreach ($options as $key=>$val) { - // header-/footer-html expect a URL or a file name, so we need to create a tmp file for HTML content - if (is_string($val) && preg_match('/^(header|footer)-html$/', $key)) { + // header-/footer-html, xsl-style-sheet and user-style-sheet expect an URL or a file name, so we need to create a tmp file for the content + if (is_string($val) && preg_match('/^((header|footer)-html|xsl-style-sheet|user-style-sheet)$/', $key) ) { defined('PHP_MAXPATHLEN') || define('PHP_MAXPATHLEN', 255); $isFile = (strlen($val) <= PHP_MAXPATHLEN) ? is_file($val) : false; if (!($isFile || preg_match('/^(https?:)?\/\//i',$val) || $val===strip_tags($val))) { From e12ed5e5a5dc1c68feb41a514ef89d1f61082610 Mon Sep 17 00:00:00 2001 From: rahxam Date: Fri, 21 Jul 2017 14:36:49 +0200 Subject: [PATCH 2/2] Update Pdf.php Simplifies regular expression, which matches options that expect an URL or a file name and transfers the regular expression into constant `REGEX_OPTS_TMPFILE`. --- src/Pdf.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Pdf.php b/src/Pdf.php index 03081d9..7f8b1b3 100644 --- a/src/Pdf.php +++ b/src/Pdf.php @@ -23,6 +23,9 @@ class Pdf // Regular expression to detect XML strings const REGEX_XML = '/<\??xml/i'; + // Regular expression to detect options that expect an URL or a file name, so we need to create a tmp file for the content. + const REGEX_OPTS_TMPFILE = '/^((header|footer)-html|(xsl|user)-style-sheet)$/i'; + // prefix for tmp files const TMP_PREFIX = 'tmp_wkhtmlto_pdf_'; @@ -300,7 +303,7 @@ protected function processOptions($options=array()) { foreach ($options as $key=>$val) { // header-/footer-html, xsl-style-sheet and user-style-sheet expect an URL or a file name, so we need to create a tmp file for the content - if (is_string($val) && preg_match('/^((header|footer)-html|xsl-style-sheet|user-style-sheet)$/', $key) ) { + if (is_string($val) && preg_match(self::REGEX_OPTS_TMPFILE, $key) ) { defined('PHP_MAXPATHLEN') || define('PHP_MAXPATHLEN', 255); $isFile = (strlen($val) <= PHP_MAXPATHLEN) ? is_file($val) : false; if (!($isFile || preg_match('/^(https?:)?\/\//i',$val) || $val===strip_tags($val))) {