From b9225fd26f07b1c2b7cbffeb5366390c7a7d2f26 Mon Sep 17 00:00:00 2001 From: Fabian Mueller Date: Fri, 19 Jun 2015 03:30:25 +0200 Subject: [PATCH 1/2] Update .gitignore to not check in PDFs --- .gitignore | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 6709c76..9fe4328 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,4 @@ -google.pdf -yahoo.pdf +*.pdf tests/shoflo.js shoflo.js -google2.pdf -html.pdf node_modules From 57aabfc77d0272e09a30d6e03456e552480dd728 Mon Sep 17 00:00:00 2001 From: Fabian Mueller Date: Fri, 19 Jun 2015 03:34:08 +0200 Subject: [PATCH 2/2] Unescape quotes and exclamation marks that are affeced by the shell-quote problem --- render.js | 6 +++++- tests/pdf.js | 24 +++++++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/render.js b/render.js index 2d06bd0..ce6f4af 100644 --- a/render.js +++ b/render.js @@ -13,7 +13,11 @@ if (phantom.args.length < 2) { console.log('incorrect args'); phantom.exit(); } else { - var options = JSON.parse(phantom.args[2]); + var optionsStr = phantom.args[2]; + // fix various escapings + optionsStr = optionsStr.replace(/\\!/g, '!'); // fix escaping of exclamation mark + optionsStr = optionsStr.replace(/\\\\"/g, '\\"'); // fix double escape of quot chars + var options = JSON.parse(optionsStr); contentsCb(options.paperSize.header); contentsCb(options.paperSize.footer); diff --git a/tests/pdf.js b/tests/pdf.js index 54d4411..267b1c9 100644 --- a/tests/pdf.js +++ b/tests/pdf.js @@ -56,7 +56,29 @@ describe('pdf#content', function() { assert.ok(false); d(); }); - }) + }); + + it('fixes shell escaping in content', function(d){ + this.timeout(5000); + var args = { content: 'PDF
' }; + var pdf = new Pdf(null, 'html2.pdf', args); + pdf.on('done', function(file){ + assert.equal(FP + '/html2.pdf', file); + d(); + }); + + }); + + it('fixes shell escaping in content (issue #33)', function(d){ + this.timeout(5000); + var args = { content: 'google' }; + var pdf = new Pdf(null, 'html3.pdf', args); + pdf.on('done', function(file){ + assert.equal(FP + '/html3.pdf', file); + d(); + }); + + }); }); describe('pdf#done() 2', function(){