Skip to content

Commit

Permalink
Fix placekey_format_is_valid() function for invalid placekey (#18)
Browse files Browse the repository at this point in the history
* Make sure placekey_format_is_valid() function does throw ValueError when there are multiple @ in the placekey.

* Update unit test to use a valid where part but multiple @ symbols.
  • Loading branch information
medhatgayed authored Nov 21, 2022
1 parent 6d13e53 commit fa48f29
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 4 additions & 1 deletion placekey/placekey.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,10 @@ def placekey_format_is_valid(placekey):
:return: True if the Placekey is valid, False otherwise
"""
what, where = _parse_placekey(placekey)
try:
what, where = _parse_placekey(placekey)
except ValueError:
return False

if what:
return _where_part_is_valid(where) and bool(WHAT_REGEX.match(what))
Expand Down
1 change: 1 addition & 0 deletions placekey/tests/test_placekey.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ def test_placekey_format_is_valid(self):
'short poi encoding')

self.assertFalse(pk.placekey_format_is_valid('@abc-234-xyz'), 'invalid where value')
self.assertFalse(pk.placekey_format_is_valid('@@5vg-7gq-tvz'), 'multiple @ in placekey')

def test_where_part_is_valid(self):
"""
Expand Down

0 comments on commit fa48f29

Please sign in to comment.