Skip to content

Commit

Permalink
Bail on unknown specified script
Browse files Browse the repository at this point in the history
  • Loading branch information
mhosken committed Apr 30, 2024
1 parent 9f831e5 commit 3a1b7bd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/langfontfinder/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ def _getmatch(self, lng, scr, reg, var, regnum):

def match(self, lng, scr, reg, var):
"""Given broken out lang tag components, return the rule result that matches."""
if scr is not None and len(scr) and scr not in self.scrrules[1]:
return None # bail on unknown script
res = self._getmatch(
lng, scr, reg, var, self.scrrules[1].get(scr, self.scrrules[0])
)
Expand Down
12 changes: 12 additions & 0 deletions test/testapi
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,17 @@ def test_lang_en():
res = response.json()
assert res['defaultfamily'][0] == 'charissil'

def test_bad_script():
response = client.get("/lang/en-Fred")
assert response.status_code == 404

def test_unknown_script():
response = client.get("/lang/en-Latf")
assert response.status_code == 200
res = response.json()
assert res['defaultfamily'][0] == ''

if __name__ == "__main__":
test_lang_en()
test_bad_script()
test_unknown_script()

0 comments on commit 3a1b7bd

Please sign in to comment.