Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion capa/rules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1374,7 +1374,7 @@ def move_to_end(m, k):
# see #263
# only do this for the features section, so the meta description doesn't get reformatted
# assumes features section always exists
features_offset = doc.find("features")
features_offset = doc.index("\n features:") + 1
doc = doc[:features_offset] + doc[features_offset:].replace(" description:", " description:")

# for negative hex numbers, yaml dump outputs:
Expand Down
21 changes: 21 additions & 0 deletions tests/test_fmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,24 @@ def test_rule_reformat_string_description():

rule = capa.rules.Rule.from_yaml(src)
assert rule.to_yaml() == src


def test_rule_reformat_meta_description_with_features_namespace():
src = textwrap.dedent("""
rule:
meta:
name: test rule
namespace: impact/features
authors:
- user@domain.com
description: test description
scopes:
static: function
dynamic: process
features:
- number: 1
""").lstrip()

formatted = capa.rules.Rule.from_yaml(src).to_yaml()
capa.rules.Rule.from_yaml(formatted)
assert formatted == src
Loading