Closed greengiraffe closed 5 years ago
Thanks! Fix published in http-link-header@1.0.1
Checking the length of the array seems like a cleaner solution to me. That way, the return type for get()
is always an Array.
We could also speed up has()
in the friendly case. e.g. has()
has it's own implementation and breaking out of the search if an attr
with the given value
is found. It'd save a bit of memory as well.
@dhui feel free to send a PR :)
Problem
Link.has('someattr', 'somevalue')
always returns true, even if'someattr'
and'somevalue'
are not present in link header.Technical description
This is what
Link.has(attr, value)
(Line #101) looks like:It checks if
Link.get(attr, value)
returnednull
.Link.get(attr, value)
(Line #83) always returns an Array, nevernull
. In case the provided attr/value pair is not present, an empty array is returned. An empty array is truthy and notnull
, thusLink.has
always returnstrue
.Solution
Either change
Link.has
to check forthis.get( attr, value ).length
or updateLink.get
to return null when the array is empty. I tend to prefer the latter, because then the returned value is falsy.