andrewrk / juice

Juice inlines CSS stylesheets into your HTML source.
MIT License
60 stars 13 forks source link

Windows : TypeError: Arguments to path.join must be strings #22

Open bhamon opened 9 years ago

bhamon commented 9 years ago

On Windows, parsing fails to retrieve the href'd file.

Full stack trace of the exception :

TypeError: Arguments to path.join must be strings
    at f (path.js:204:15)
    at Object.filter (native)
    at Object.exports.join (path.js:209:40)
    at getHrefContent (D:\_data\_perso\_dev\nodejs\reminder\node_modules\swig-email-templates\node_modules\juice2\lib\juice.js:306:25)
    at D:\_data\_perso\_dev\nodejs\reminder\node_modules\swig-email-templates\node_modules\juice2\lib\juice.js:365:7
    at pendGo (D:\_data\_perso\_dev\nodejs\reminder\node_modules\swig-email-templates\node_modules\juice2\node_modules\pend\index.js:30:3)
    at Pend.go (D:\_data\_perso\_dev\nodejs\reminder\node_modules\swig-email-templates\node_modules\juice2\node_modules\pend\index.js:13:5)
    at D:\_data\_perso\_dev\nodejs\reminder\node_modules\swig-email-templates\node_modules\juice2\lib\juice.js:363:10
    at Array.forEach (native)
    at extractCssFromDocument (D:\_data\_perso\_dev\nodejs\reminder\node_modules\swig-email-templates\node_modules\juice2\lib\juice.js:362:40)

Correction :

Replace

var filePath = path.join(sourceHref.split("file:" + path.sep)[1], destHref); //linux

With

var filePath = path.join(sourceHref.split("file:/")[1], destHref); //linux
afloyd commented 9 years ago

this seemed to work for me in windows with the existing juice library in windows:

var path = require('path');
juice.juiceContent(html, {
        url: 'file:' + path.sep + path.sep + 'styles' + path.sep
    }, function renderTemplate(err, html) {
        // do something
    });
bhamon commented 9 years ago

Your example would mean that the final URI is file:\\styles\ on Windows (as the path.sep var equals to \ on Windows platforms) which is incorrect (see http://en.wikipedia.org/wiki/File_URI_scheme or http://blogs.msdn.com/b/ie/archive/2006/12/06/file-uris-in-windows.aspx).

In my particular case, I use the swig-email-templates node module which gives juice a path that looks like file://c:\path\to\style.css when I specify a <link rel="stylesheet" href="style.css"> tag in my template. The file:// part is more correct on this example, even if it's still incorrect regarding to the URI RFCs.

afloyd commented 9 years ago

I totally agree the example I give will format as you've shown, and it's not to the URI schema spec... But I know that it works with the current implementation of how juice parses a link href

amitgur commented 9 years ago

I'm having the same problem. @bhamon soultion worked for me. can It be merged to juice ?