Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix NilAccept.best_match() so an empty "offers" + default_match picks…

… default

Prior to this, NilAccept.best_match([], default_match="default") threw:
UnboundLocalError: local variable 'best_offer' referenced before assignment

Also added a relevant test.
  • Loading branch information...
commit 23a3c3b30781df3a548a5d3f786190d41ab51e95 1 parent d6de19b
@cwebber cwebber authored
Showing with 2 additions and 2 deletions.
  1. +1 −1  tests/test_acceptparse.py
  2. +1 −1  webob/acceptparse.py
View
2  tests/test_acceptparse.py
@@ -208,11 +208,11 @@ def test_nil_best_match():
assert nilaccept.best_match([('foo', 1), ('bar', 0.5)]) == 'foo'
assert nilaccept.best_match([('foo', 0.5), ('bar', 1)]) == 'bar'
assert nilaccept.best_match([('foo', 0.5), 'bar']) == 'bar'
- # default_match has no effect on NilAccept class
assert nilaccept.best_match([('foo', 0.5), 'bar'],
default_match=True) == 'bar'
assert nilaccept.best_match([('foo', 0.5), 'bar'],
default_match=False) == 'bar'
+ assert nilaccept.best_match([], default_match='fallback') == 'fallback'
# NoAccept tests
View
2  webob/acceptparse.py
@@ -224,7 +224,7 @@ def first_match(self, offers): # pragma: no cover
def best_match(self, offers, default_match=None):
best_quality = -1
- best_match = default_match
+ best_offer = default_match
for offer in offers:
_check_offer(offer)
if isinstance(offer, (list, tuple)):
Please sign in to comment.
Something went wrong with that request. Please try again.