Files
firefox/tools/lint/test/test_trojan_source.py
Sylvestre Ledru 0315328b09 Bug 2023411 - Rewrite trojan-source linter in Rust with Python wrapper r=linter-reviewers,ahal,sergesanspaille
Replaces the Python Unicode format-character detection with the
mozcheck Rust binary. Scans for Unicode Cf category characters
(CVE-2021-42572) in parallel using rayon.

This also improves the linter: the previous Python implementation
stopped on the first offending line per file, while the Rust
implementation reports every line containing a disallowed character.

Differential Revision: https://phabricator.services.mozilla.com/D288086
2026-04-24 16:08:41 +00:00

39 lines
1.1 KiB
Python

import mozunit
LINTER = "trojan-source"
def test_lint_trojan_source(lint, paths):
results = lint(paths())
print(results)
assert len(results) == 5
assert "disallowed characters" in results[0].message
assert results[0].level == "error"
assert "commenting-out.cpp" in results[0].relpath
assert results[0].lineno == 5
assert "disallowed characters" in results[1].message
assert results[1].level == "error"
assert "commenting-out.cpp" in results[1].relpath
assert results[1].lineno == 7
assert "disallowed characters" in results[2].message
assert results[2].level == "error"
assert "early-return.py" in results[2].relpath
assert results[2].lineno == 5
assert "disallowed characters" in results[3].message
assert results[3].level == "error"
assert "invisible-function.rs" in results[3].relpath
assert results[3].lineno == 5
assert "disallowed characters" in results[4].message
assert results[4].level == "error"
assert "invisible-function.rs" in results[4].relpath
assert results[4].lineno == 10
if __name__ == "__main__":
mozunit.main()