Skip to content

Commit

Permalink
Fixed backslash in rebased paths on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
bezoerb committed Oct 18, 2014
1 parent f95d2fc commit a93bcb4
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
17 changes: 17 additions & 0 deletions fixture/index-image-path.html
@@ -0,0 +1,17 @@
<!doctype html>
<html class="no-js">
<head>
<meta charset="utf-8">
<title>critical css test</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">

<link rel="stylesheet" href="styles/path/image.css">
</head>
<body>
<div class="container">
<div class="header">
</div>
</div>
</body>
</html>
10 changes: 9 additions & 1 deletion index.js
Expand Up @@ -6,6 +6,7 @@
'use strict';
var fs = require('fs');
var path = require('path');
var slash = require('slash');
var penthouse = require('penthouse');
var CleanCSS = require('clean-css');
var oust = require('oust');
Expand All @@ -21,6 +22,13 @@ var uuid = require('uuid');
Promise.promisifyAll(fs);
var penthouseAsync = Promise.promisify(penthouse);

/**
* Fixup slashes in file paths for windows
*/
function normalizePath(str) {
return process.platform === 'win32' ? slash(str) : str;
}


/**
* Critical path CSS generation
Expand Down Expand Up @@ -86,7 +94,7 @@ exports.generate = function (opts, cb) {
var relativeToBase = path.relative(path.resolve(opts.base), path.resolve(path.join(dir, filePath)));

// prepend / to make it absolute
return match.replace(filePath, path.join('/', relativeToBase));
return normalizePath(match.replace(filePath, path.join('/', relativeToBase)));
});
});

Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -29,6 +29,7 @@
"inline-critical": "0.0.4",
"oust": "^0.2.0",
"penthouse": "^0.2.5",
"slash": "^1.0.0",
"uuid": "~2.0.1"
},
"devDependencies": {
Expand Down
14 changes: 14 additions & 0 deletions test.js
Expand Up @@ -308,4 +308,18 @@ it('inlines critical-path CSS ignoring remote stylesheets', function (done) {
assert.strictEqual(stripWhitespace(output), stripWhitespace(expected));
done();
});
});

it('does not screw up width win32 paths', function (done) {
critical.generate({
base: 'fixture/',
src: 'index-image-path.html',
inlineImages: false
}, function (err, output) {
assert.strictEqual(
stripWhitespace(output),
stripWhitespace('.header{ background: transparent url(\'/images/critical.png\'); }')
);
done();
});
});

0 comments on commit a93bcb4

Please sign in to comment.