Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into testcov
Browse files Browse the repository at this point in the history
  • Loading branch information
dhui committed Dec 6, 2018
2 parents 323f68e + 57fa842 commit f759b66
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 6 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Jonas Hermsmeier <[email protected]>
Dale Hui <[email protected]>
Matteo Brancaleoni <[email protected]>
Yamagishi Kazutoshi <[email protected]>
15 changes: 14 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

## v1.0.2

- Make `.get()` have a consistent return type ([@dhui])
- Improve `.has()` best-case performance ([@dhui])
- Fix `.has()` test and add a test for the negative case ([@dhui])

## v1.0.1

- Fix `link.has()` always returning `true`

## v1.0.0

**Breaking Changes:**
Expand All @@ -14,4 +24,7 @@
- Fixed handling of backslash-escaped characters
- Fixed missing cardinality handling for `type`, `media` and `title` attributes
- Fixed handling of leading / trailing whitespace around delimiters
- Replace `querystring.*()` with `xxcodeURIComponent()` ([@ykzts](https://github.com/ykzts))
- Replace `querystring.*()` with `xxcodeURIComponent()` ([@ykzts])

[@ykzts]: https://github.com/ykzts
[@dhui]: https://github.com/dhui
16 changes: 13 additions & 3 deletions lib/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class Link {
* Get refs where given attribute has a given value
* @param {String} attr
* @param {String} value
* @returns {Array<Object>|null}
* @returns {Array<Object>}
*/
get( attr, value ) {

Expand All @@ -88,7 +88,7 @@ class Link {
}
}

return links.length ? links : null
return links

}

Expand All @@ -98,7 +98,17 @@ class Link {
}

has( attr, value ) {
return this.get( attr, value ) != null

attr = attr.toLowerCase()

for( var i = 0; i < this.refs.length; i++ ) {
if( this.refs[ i ][ attr ] === value ) {
return true
}
}

return false

}

parse( value, offset ) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "http-link-header",
"version": "1.0.1",
"version": "1.0.2",
"description": "Parse & format HTTP link headers according to RFC 8288",
"author": "Jonas Hermsmeier <[email protected]> (https://jhermsmeier.de)",
"license": "MIT",
Expand Down
8 changes: 7 additions & 1 deletion test/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ suite( 'API', function() {
test( 'has("rel", "next")', function() {
var link = Link.parse( '<https://acme-staging.api.letsencrypt.org/acme/new-authz>;rel="next", <https://letsencrypt.org/documents/LE-SA-v1.1.1-August-1-2016.pdf>;rel="terms-of-service"' )
// console.log( inspect( link.has( 'rel', 'next' ) ) )
assert.deepEqual( link.has( 'next' ), true )
assert.deepEqual( link.has( 'rel', 'next' ), true )
})

test( 'has("rel", "prev")', function() {
var link = Link.parse( '<https://acme-staging.api.letsencrypt.org/acme/new-authz>;rel="next", <https://letsencrypt.org/documents/LE-SA-v1.1.1-August-1-2016.pdf>;rel="terms-of-service"' )
// console.log( inspect( link.has( 'rel', 'prev' ) ) )
assert.deepEqual( link.has( 'rel', 'prev' ), false )
})

test( 'toString()', function() {
Expand Down

0 comments on commit f759b66

Please sign in to comment.