p-meier / hapi-api-version

An API versioning plugin for hapi.
Apache License 2.0
74 stars 26 forks source link

The RegExp that matches the vendorName is more restricted than it should #21

Closed j-a-m-l closed 5 years ago

j-a-m-l commented 6 years ago

The vendorField could follow the schema provided by the specification (https://tools.ietf.org/html/rfc6838#section-4.2), so the RegExp that extracts it from the accept header should be fixed to allow other characters than alphanumeric:

https://github.com/p-meier/hapi-api-version/blob/5c5b57fbaebaba8e6969aa0236a3cc1d30f7c297/index.js#L37

timcosta commented 5 years ago

If you'd like to PR an update for this please feel free, otherwise I'll add support in the next week or two. I think ideally the regex would look like

/^vnd.[^\s\.]+\.v[0-9]+$/

Would this solve your needs?

j-a-m-l commented 5 years ago

Thanks for you answer.

That RegExp would be enough for me, although I'd use a different one, to adhere to the specification.

A different issue, that I've found when running the tests, is that some of them look incorrect:

For instance, this one shouldn't throw an Error: https://github.com/p-meier/hapi-api-version/blob/5c5b57fbaebaba8e6969aa0236a3cc1d30f7c297/test/index.js#L196

I'd like to contribute with the PR of the RegExp, but would you mind to confirm if those tests are correct?