mirror of
https://github.com/mandiant/capa.git
synced 2025-12-05 20:40:05 -08:00
better deal with CRLF/LF issues
This commit is contained in:
@@ -736,6 +736,8 @@ class Rule(object):
|
||||
# the below regex makes these adjustments and while ugly, we don't have to explore the ruamel.yaml insides
|
||||
doc = re.sub(r"!!int '0x-([0-9a-fA-F]+)'", r"-0x\1", doc)
|
||||
|
||||
# normalize CRLF to LF
|
||||
doc = doc.replace("\r\n", "\n")
|
||||
return doc
|
||||
|
||||
|
||||
|
||||
@@ -65,6 +65,8 @@ def main(argv=None):
|
||||
return 0
|
||||
else:
|
||||
logger.info("rule requires reformatting (%s)", rule.name)
|
||||
if "\r\n" in rule.definition:
|
||||
logger.info("please make sure that the file uses LF (\\n) line endings only")
|
||||
return 1
|
||||
|
||||
if args.in_place:
|
||||
|
||||
@@ -331,7 +331,12 @@ class FormatIncorrect(Lint):
|
||||
|
||||
if actual != expected:
|
||||
diff = difflib.ndiff(actual.splitlines(1), expected.splitlines(True))
|
||||
self.recommendation = self.recommendation_template.format("".join(diff))
|
||||
recommendation_template = self.recommendation_template
|
||||
if "\r\n" in actual:
|
||||
recommendation_template = (
|
||||
self.recommendation_template + "\nplease make sure that the file uses LF (\\n) line endings only"
|
||||
)
|
||||
self.recommendation = recommendation_template.format("".join(diff))
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user