Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var Promise = require('es6-promise').Promise; // jshint ignore:line
var fs = require('then-fs');
var mime = require('mime');
var basename = require('path').basename;
var { URL } = require('url');

var cache = {};

Expand Down Expand Up @@ -71,7 +72,12 @@ module.exports = function get(url, options) {
debug('request %s', url, settings);

cache[url] = new Promise(function (resolve) {
request(encodeURI(url), settings, function response(error, res, body) {
var encodedUrl = new URL(url).toString();
if (encodedUrl !== url) {
inliner.emit('warning', 'url ' + url + ' was transformed to ' +
encodedUrl);
}
request(encodedUrl, settings, function response(error, res, body) {
if (error) {
debug('request failed: %s', error.message);
inliner.emit('warning', 'failed to request ' + base + ' (' +
Expand Down
Binary file added test/fixtures/Encoded Space.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion test/fixtures/bad-url.result.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<img src="data:undefined;base64,">
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this is bad or not. I couldn't quite figure out why it's getting a HTML page out of the sudden.

<img src="data:text/html;base64,">
1 change: 1 addition & 0 deletions test/fixtures/image-inline-encoded-space.result.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>inline image with encoded space in the name</title> </head> <body> <img src="data:image/gif;base64,R0lGODlhAQABAIABAP///wAAACwAAAAAAQABAAACAkQBADs="> </body> </html>
10 changes: 10 additions & 0 deletions test/fixtures/image-inline-encoded-space.src.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>inline image with encoded space in the name</title>
</head>
<body>
<img src="http://localhost:54321/Encoded%20Space.gif">
</body>
</html>