Skip to content

Commit

Permalink
[localecfg] Be slightly more conservative interpreting comments
Browse files Browse the repository at this point in the history
 - A valid line (as explained in the comments at the top of
   the locale.gen file) is <locale> <encoding> (two fields),
   so lines with more than two fields can't be valid locale-
   listing lines. For them, pretend they name locale "",
   which won't be matched.
  • Loading branch information
adriaandegroot committed Jun 20, 2018
1 parent 8551653 commit 25f2491
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/modules/localecfg/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def is_comment(line):
"""
return bool(RE_IS_COMMENT.match(line))

RE_TRAILING_COMMENT = re.compile("#.*$")
RE_REST_OF_LINE = re.compile("\\s.*$")
def extract_locale(line):
"""
Expand All @@ -46,9 +47,14 @@ def extract_locale(line):
# Remove leading spaces and comment signs
line = RE_IS_COMMENT.sub("", line)
uncommented = line.strip()
# Drop all but first field
locale = RE_REST_OF_LINE.sub("", uncommented)
return locale, uncommented
fields = RE_TRAILING_COMMENT.sub("", uncommented).strip().split()
if len(fields) != 2:
# Not exactly two fields, can't be a proper locale line
return "", uncommented
else:
# Drop all but first field
locale = RE_REST_OF_LINE.sub("", uncommented)
return locale, uncommented


def rewrite_locale_gen(srcfilename, destfilename, locale_conf):
Expand Down

0 comments on commit 25f2491

Please sign in to comment.