diff --git a/lib/langfontfinder/__init__.py b/lib/langfontfinder/__init__.py index d434787..78cbd95 100644 --- a/lib/langfontfinder/__init__.py +++ b/lib/langfontfinder/__init__.py @@ -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]) ) diff --git a/test/testapi b/test/testapi index 7f88142..e3ad603 100755 --- a/test/testapi +++ b/test/testapi @@ -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()