Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d654b6f9 authored by Deepanshu Gupta's avatar Deepanshu Gupta
Browse files

Be lenient in accepting version strings.

Don't throw exceptions for malformed version strings in font files, and
try to rename the font as is.

Change-Id: Ib4f74e68593abb5b551fbcb049484efc925a3d6e
parent 6fd1705f
Loading
Loading
Loading
Loading
+8 −5
Original line number Diff line number Diff line
@@ -209,15 +209,18 @@ def ends_in_regular(string):


def get_version(string):
  # The string must begin with 'Version n.nn '
  # to extract n.nn, we return the second entry in the split strings.
  string = string.strip()
  if not string.startswith('Version '):
    raise InvalidFontException('mal-formed font version')
  return sanitize(string.split()[1])
  # The spec says that the version string should start with "Version ". But not
  # all fonts do. So, we return the complete string if it doesn't start with
  # the prefix, else we return the rest of the string after sanitizing it.
  prefix = 'Version '
  if string.startswith(prefix):
    string = string[len(prefix):]
  return sanitize(string)


def sanitize(string):
  """ Remove non-standard chars. """
  return re.sub(r'[^\w-]+', '', string)

if __name__ == '__main__':
+8 −5
Original line number Diff line number Diff line
@@ -193,15 +193,18 @@ def ends_in_regular(string):


def get_version(string):
  # The string must begin with 'Version n.nn '
  # to extract n.nn, we return the second entry in the split strings.
  string = string.strip()
  if not string.startswith('Version '):
    raise InvalidFontException('mal-formed font version')
  return sanitize(string.split()[1])
  # The spec says that the version string should start with "Version ". But not
  # all fonts do. So, we return the complete string if it doesn't start with
  # the prefix, else we return the rest of the string after sanitizing it.
  prefix = 'Version '
  if string.startswith(prefix):
    string = string[len(prefix):]
  return sanitize(string)


def sanitize(string):
  """ Remove non-standard chars. """
  return re.sub(r'[^\w-]+', '', string)

if __name__ == '__main__':