rules: factor out DESCRIPTION_SEPARATOR into a constant

closes #87
This commit is contained in:
William Ballenthin
2020-07-06 16:54:40 -06:00
parent 959b66b26a
commit ca175f02c7
2 changed files with 11 additions and 4 deletions

View File

@@ -82,7 +82,7 @@ def render_feature(ostream, match, feature, indent=0):
ostream.write(rutils.bold2(feature[feature["type"]]))
if "description" in feature:
ostream.write(" = ")
ostream.write(capa.rules.DESCRIPTION_SEPARATOR)
ostream.write(feature["description"])
render_locations(ostream, match)

View File

@@ -207,16 +207,23 @@ def parse_feature(key):
raise InvalidRule("unexpected statement: %s" % key)
# this is the separator between a feature value and its description
# when using the inline description syntax, like:
#
# number: 42 = ENUM_FAVORITE_NUMBER
DESCRIPTION_SEPARATOR = " = "
def parse_description(s, value_type, description=None):
"""
s can be an int or a string
"""
if value_type != "string" and isinstance(s, six.string_types) and " = " in s:
if value_type != "string" and isinstance(s, six.string_types) and DESCRIPTION_SEPARATOR in s:
if description:
raise InvalidRule(
'unexpected value: "%s", only one description allowed (inline description with ` = `)' % s
'unexpected value: "%s", only one description allowed (inline description with `%s`)' % (s, DESCRIPTION_SEPARATOR)
)
value, _, description = s.rpartition(" = ")
value, _, description = s.rpartition(DESCRIPTION_SEPARATOR)
if description == "":
raise InvalidRule('unexpected value: "%s", description cannot be empty' % s)
else: