Commit b5e5632e authored by Iustin Pop's avatar Iustin Pop
Browse files

Allow '@' in tag values



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: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent f7e41aa2
...@@ -210,9 +210,10 @@ class TaggableObject(ConfigObject): ...@@ -210,9 +210,10 @@ class TaggableObject(ConfigObject):
""" """
__slots__ = ConfigObject.__slots__ + ["tags"] __slots__ = ConfigObject.__slots__ + ["tags"]
VALID_TAG_RE = re.compile("^[\w.+*/:@-]+$")
@staticmethod @classmethod
def ValidateTag(tag): def ValidateTag(cls, tag):
"""Check if a tag is valid. """Check if a tag is valid.
If the tag is invalid, an errors.TagError will be raised. The If the tag is invalid, an errors.TagError will be raised. The
...@@ -226,7 +227,7 @@ class TaggableObject(ConfigObject): ...@@ -226,7 +227,7 @@ class TaggableObject(ConfigObject):
constants.MAX_TAG_LEN) constants.MAX_TAG_LEN)
if not tag: if not tag:
raise errors.TagError("Tags cannot be empty") 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") raise errors.TagError("Tag contains invalid characters")
def GetTags(self): def GetTags(self):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment