Skip to content

Commit

Permalink
fix: spaces in file names
Browse files Browse the repository at this point in the history
Fixes inlining local files with spaces in names.
Fixes remy#148.
  • Loading branch information
positronium authored and remy committed Jun 25, 2017
1 parent 5786954 commit c3cbdf0
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/spaces in names.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
body {
background-color: #222;
color: wheat;
}
1 change: 1 addition & 0 deletions test/fixtures/spaces in names.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log("Hi");
1 change: 1 addition & 0 deletions test/fixtures/spaces in names.result.html
Original file line number Diff line number Diff line change
@@ -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 changes: 12 additions & 0 deletions test/fixtures/spaces in names.src.html
Original file line number Diff line number Diff line change
@@ -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>

0 comments on commit c3cbdf0

Please sign in to comment.