Skip to content

Commit

Permalink
add-designer: validate name
Browse files Browse the repository at this point in the history
  • Loading branch information
m4rc1e committed Jun 15, 2021
1 parent 70974c5 commit 3a3c91e
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion bin/gftools-add-designer.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,19 @@ def gen_hrefs(urls):
return " | ".join(f"<a href={k}>{v}</a>" for k,v in res.items())


def designer_name(name):
"""Google Fonts only accepts designer names which use the Latin script"""
# Check all characters are within range U+0000 - U+024F (Basic Latin - Latin Ex-B)
# https://www.compart.com/en/unicode/plane/U+0000
invalid_chars = [c for c in name if ord(c) > 0x024F]
if invalid_chars:
raise argparse.ArgumentTypeError(
f"'{name}' has the following illegal characters {invalid_chars}. "
"Please Latinize names."
)
return name


def make_designer(
designer_directory,
name,
Expand Down Expand Up @@ -149,7 +162,7 @@ def make_designer(
def main():
parser = argparse.ArgumentParser(usage=__doc__)
parser.add_argument("designers_directory", help="path to google/fonts designer dir")
parser.add_argument("name", help="Designer name e.g 'Steve Matteson'")
parser.add_argument("name", help="Designer name e.g 'Steve Matteson'", type=designer_name)
parser.add_argument("--img_path", help="Optional path to profile image", default=None)
parser.add_argument(
"--spreadsheet", help="Optional path to the Google Drive spreadsheet"
Expand Down

0 comments on commit 3a3c91e

Please sign in to comment.