3rd-Eden / useragent

Useragent parser for Node.js, ported from browserscope.org
MIT License
897 stars 137 forks source link

'satisfies' method sometimes failed #44

Closed klimashkin closed 10 years ago

klimashkin commented 10 years ago

Hello! If I have Opera 12.00, useragent returns me

{major: '12', minor: '00', patch: '0'}

And then semver 'satisfies' returns error

TypeError: Invalid Version: 12.00.0

because

Agent.prototype.satisfies = function satisfies (range) {
  return semver.satisfies(this.major + '.' + this.minor + '.' + this.patch, range);
};

Maybe it must be like this

Agent.prototype.satisfies = function satisfies (range) {
  return semver.satisfies((Number(this.major) || 0) + '.' + (Number(this.minor) || 0) + '.' + (Number(this.patch) || 0), range);
};
3rd-Eden commented 10 years ago

Yes, that's because the satisfies assumes that the versioning scheme follows the semver specification. Parsing the values down to number would probably be a good idea. Could you create a pull request for that?