From 25f249180b40f95958601f5d2431a365bd6ce2a8 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 20 Jun 2018 09:11:23 -0400 Subject: [PATCH] [localecfg] Be slightly more conservative interpreting comments - A valid line (as explained in the comments at the top of the locale.gen file) is (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. --- src/modules/localecfg/main.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/modules/localecfg/main.py b/src/modules/localecfg/main.py index bf41e6317b..62a00b738d 100644 --- a/src/modules/localecfg/main.py +++ b/src/modules/localecfg/main.py @@ -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): """ @@ -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):