fix: spaces in file names

Fixes inlining local files with spaces in names.
Fixes #148.
This commit is contained in:
positronium 2017-06-25 20:31:09 +03:00 committed by Remy Sharp
parent 5786954e07
commit c3cbdf0346
5 changed files with 25 additions and 1 deletions

View File

@ -31,7 +31,13 @@ module.exports = function get(url, options) {
if (this.isFile && url.indexOf('http') !== 0) {
debug('inliner.get file: %s', url);
cache[url] = fs.readFile(url).then(function read(body) {
cache[url] = fs.readFile(url).catch(function (error) {
if (error.code === 'ENOENT' || error.code === 'ENAMETOOLONG') {
debug(error.code + ': ' + base + ', trying decodeURI');
return fs.readFile(decodeURI(url));
}
throw error;
}).then(function read(body) {
return {
body: body,
headers: {

4
test/fixtures/spaces in names.css vendored Normal file
View File

@ -0,0 +1,4 @@
body {
background-color: #222;
color: wheat;
}

1
test/fixtures/spaces in names.js vendored Normal file
View File

@ -0,0 +1 @@
console.log("Hi");

View File

@ -0,0 +1 @@
<!DOCTYPE html> <html> <head> <title>Spaces in file names test</title> <meta charset="UTF-8"> <style>body{ background-color:#222;color:wheat;}</style> <script type="text/javascript">console.log("Hi");</script> </head> <body> <div>Some content</div> </body> </html>

12
test/fixtures/spaces in names.src.html vendored Normal file
View File

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<title>Spaces in file names test</title>
<meta charset="UTF-8">
<link rel="stylesheet" href="spaces%20in%20names.css" />
<script type="text/javascript" src="spaces%20in%20names.js"></script>
</head>
<body>
<div>Some content</div>
</body>
</html>