emerleite / node-gravatar

Node.JS library to generate gravatar URLs
420 stars 52 forks source link

Base URL formatted incorrectly #47

Open somemothersson opened 5 years ago

somemothersson commented 5 years ago

var baseURL,fix leading // to instead be https:// when gravatar url is created via gravatar.url(email) the url is generated as //www.gravatar.com when should be https://www.gravatar.com

line 32 gravatar.js

var gravatar = module.exports = {

    url: function (email, options, protocol) {
      var baseURL = "//www.gravatar.com/avatar/";
      if (options && options.cdn) {
        baseURL = options.cdn + '/avatar/';
        delete options.cdn;
      } else {
        if (options && options.protocol) protocol = proto(options);
        if(typeof protocol !== 'undefined') {
          baseURL = protocol ? "https://s.gravatar.com/avatar/" : 'http://www.gravatar.com/avatar/';
        }
      }
      var query = getQueryString(options);
      return baseURL + getHash(email) + query;
    },
bushblade commented 4 years ago

I can confirm this issue. We already have normalize-url installed in our project so used that to get a valid url.

dantman commented 4 years ago

Do note that //www.gravatar.com/ is still a valid href. It is a protocol relative url, i.e. on http://example.com the link will resolve to http://www.gravatar.com/.

emerleite commented 4 years ago

@somemothersson do you suggest to always use https?