emerleite / node-gravatar

Node.JS library to generate gravatar URLs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Base URL formatted incorrectly

somemothersson opened this issue · comments

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;
    },

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

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/.

@somemothersson do you suggest to always use https?