Skip to content

Commit

Permalink
Fix regression matching multiple ETags in If-None-Match
Browse files Browse the repository at this point in the history
  • Loading branch information
dougwilson committed Sep 14, 2017
1 parent e8a4aaf commit ff5f257
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
5 changes: 5 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
unreleased
==========

* Fix regression matching multiple ETags in `If-None-Match`

0.5.1 / 2017-09-11
==================

Expand Down
10 changes: 8 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,19 @@ function fresh (reqHeaders, resHeaders) {
return false
}

var etagStale = true
var matches = noneMatch.split(TOKEN_LIST_REGEXP)
for (var i = 0; i < matches.length; i++) {
var match = matches[i]
if (match !== etag && match !== 'W/' + etag && 'W/' + match !== etag) {
return false
if (match === etag || match === 'W/' + etag || 'W/' + match === etag) {
etagStale = false
break
}
}

if (etagStale) {
return false
}
}

// if-modified-since
Expand Down
8 changes: 8 additions & 0 deletions test/fresh.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ describe('fresh(reqHeaders, resHeaders)', function () {
})
})

describe('when at least one matches', function () {
it('should be fresh', function () {
var reqHeaders = { 'if-none-match': ' "bar" , "foo"' }
var resHeaders = { 'etag': '"foo"' }
assert.ok(fresh(reqHeaders, resHeaders))
})
})

describe('when etag is missing', function () {
it('should be stale', function () {
var reqHeaders = { 'if-none-match': '"foo"' }
Expand Down

0 comments on commit ff5f257

Please sign in to comment.