mirror of
https://github.com/remy/inliner.git
synced 2024-10-26 18:49:55 +03:00
fix: non-ascii characters
When doing a request with the node request module with an URL containing UTF-8 chars, some webservers will fail to find the file. Therefore encodeURI on the url before requesting it. Not sure if this is the best way to test it, but it works with all test cases. Example of page which doesn't inline properly: http://hotpoticeland.com/holsgerdislaug/ which links to the image: http://hotpoticeland.com/wp-content/uploads/Hólsgerðislaug-300x225.jpg
This commit is contained in:
parent
6a1dec4f4c
commit
a2869fc81a
@ -65,7 +65,7 @@ module.exports = function get(url, options) {
|
|||||||
debug('request %s', url, settings);
|
debug('request %s', url, settings);
|
||||||
|
|
||||||
cache[url] = new Promise(function (resolve, reject) {
|
cache[url] = new Promise(function (resolve, reject) {
|
||||||
request(url, settings, function response(error, res, body) {
|
request(encodeURI(url), settings, function response(error, res, body) {
|
||||||
if (error) {
|
if (error) {
|
||||||
debug('request failed: %s', error.message);
|
debug('request failed: %s', error.message);
|
||||||
return reject(error);
|
return reject(error);
|
||||||
|
BIN
test/fixtures/Hólsgerðislaug-300x225.gif
vendored
Normal file
BIN
test/fixtures/Hólsgerðislaug-300x225.gif
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 35 B |
1
test/fixtures/image-inline-special-chars.result.html
vendored
Normal file
1
test/fixtures/image-inline-special-chars.result.html
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>inline image with special characters</title> </head> <body> <img src="data:image/gif;base64,R0lGODlhAQABAIABAP///wAAACwAAAAAAQABAAACAkQBADs="> </body> </html>
|
10
test/fixtures/image-inline-special-chars.src.html
vendored
Normal file
10
test/fixtures/image-inline-special-chars.src.html
vendored
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>inline image with special characters</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<img src="http://localhost:54321/Hólsgerðislaug-300x225.gif">
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -8,9 +8,17 @@ var st = require('st');
|
|||||||
var server;
|
var server;
|
||||||
|
|
||||||
test('setup mock server', function (t) {
|
test('setup mock server', function (t) {
|
||||||
server = http.createServer(
|
server = http.createServer(function(req, res) {
|
||||||
st(path.resolve(__dirname, 'fixtures'))
|
if (isASCII(req.url)) {
|
||||||
).listen(54321);
|
st(path.resolve(__dirname, 'fixtures'))(req, res);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Fail because all non-ascii chars should be urlencoded
|
||||||
|
// (some http servers don't handle non-ascii)
|
||||||
|
res.statusCode = 404;
|
||||||
|
res.end();
|
||||||
|
}
|
||||||
|
}).listen(54321);
|
||||||
|
|
||||||
server.on('listening', function listening() {
|
server.on('listening', function listening() {
|
||||||
t.pass('mock server ready');
|
t.pass('mock server ready');
|
||||||
@ -120,3 +128,7 @@ test('tear down', function (t) {
|
|||||||
t.pass('tear down complete');
|
t.pass('tear down complete');
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function isASCII(str) {
|
||||||
|
return /^[\x00-\x7F]*$/.test(str);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user