This allows using an email address (as is) as part of a tag. The main
problem that could arise is when parsing tags from a shell script, but
(AFAIK) '@' is not a special character when used in values (happy to be
corrected if not true).
The patch also moves the re to be compiled at class init time, should
use less resources; in my tests it is fine to use a compiled re from
multiple threads.
Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Guido Trotter <ultrotter@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>
"""
__slots__ = ConfigObject.__slots__ + ["tags"]
+ VALID_TAG_RE = re.compile("^[\w.+*/:@-]+$")
- @staticmethod
- def ValidateTag(tag):
+ @classmethod
+ def ValidateTag(cls, tag):
"""Check if a tag is valid.
If the tag is invalid, an errors.TagError will be raised. The
constants.MAX_TAG_LEN)
if not tag:
raise errors.TagError("Tags cannot be empty")
- if not re.match("^[\w.+*/:-]+$", tag):
+ if not cls.VALID_TAG_RE.match(tag):
raise errors.TagError("Tag contains invalid characters")
def GetTags(self):