Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
- fix: remove redundant code related to cli loading @mike-hunhoff #3076
- fix: optimize all_zeros using fast bytes comparison @mike-hunhoff #3078
- fix: duplicate rule candidate evaluation in optimized matching engine @mike-hunhoff #3080
- fix: capafmt corrupts rules whose namespace contains "features" @Makeph #3135

### capa Explorer Web

Expand Down
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