show invalid url error if request.head fails

v1.18.x
Barış Soner Uşaklı 7 years ago
parent 926b763f74
commit 108c3c980a

@ -20,6 +20,7 @@
"invalid-login-credentials": "Invalid login credentials",
"invalid-username-or-password": "Please specify both a username and password",
"invalid-search-term": "Invalid search term",
"invalid-url": "Invalid URL",
"csrf-invalid": "We were unable to log you in, likely due to an expired session. Please try again",
"invalid-pagination-value": "Invalid pagination value, must be at least %1 and at most %2",

@ -23,7 +23,12 @@ module.exports = function (User) {
async.waterfall([
function (next) {
request.head(url, next);
request.head(url, function (err, res, body) {
if (err) {
return setTimeout(next.bind(null, new Error('[[error:invalid-url]]')), err.message === 'Parse Error' ? 1000 : 0);
}
next(null, res, body);
});
},
function (res, body, next) {
var uploadSize = parseInt(meta.config.maximumProfileImageSize, 10) || 256;

@ -849,6 +849,20 @@ describe('User', function () {
});
});
it('should return error if url is invalid when uploading from url', function (done) {
function filterMethod(data, callback) {
callback(null, data);
}
plugins.registerHook('test-plugin', { hook: 'filter:uploadImage', method: filterMethod });
User.uploadFromUrl(uid, 'http://scanme.nmap.org:2234/index.html', function (err) {
assert.equal(err.message, '[[error:invalid-url]]');
done();
});
});
it('should return error if the file is too big when uploading from url', function (done) {
var url = nconf.get('url') + '/assets/logo.png';
meta.config.maximumProfileImageSize = 1;

Loading…
Cancel
Save