Node.js based forum software built for the modern web
show invalid url error if request.head fails
Barış Soner Uşaklı108c3c980a8a
diff --git a/public/language/en-GB/error.json b/public/language/en-GB/error.jsonindex 71c045efc3..7700006520 100644--- a/public/language/en-GB/error.json+++ b/public/language/en-GB/error.json@@ -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",diff --git a/src/user/picture.js b/src/user/picture.jsindex 60991aa39c..271bed47fc 100644--- a/src/user/picture.js+++ b/src/user/picture.js@@ -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;diff --git a/test/user.js b/test/user.jsindex c3ce6957aa..528774979a 100644--- a/test/user.js+++ b/test/user.js@@ -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;