mirror of
https://github.com/esphome/esphome.git
synced 2026-09-23 04:58:38 +00:00
[core] Anchor legacy redaction regex to avoid false-positive warnings
The unanchored leading \w* could match fields like 'monkey:' (via the 'key' fragment), naming a non-sensitive field in the deprecation warning. Restrict the fragment to either start the name or follow '_', so warnings only fire when there's an actual sensitive-shaped field the author can migrate.
This commit is contained in:
@@ -424,6 +424,18 @@ def test_redact_with_legacy_fallback__does_not_match_fragment_in_middle(
|
||||
assert not any("legacy substring" in rec.message for rec in caplog.records)
|
||||
|
||||
|
||||
def test_redact_with_legacy_fallback__does_not_match_fragment_as_suffix(
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Fragment must start the name or follow ``_``; ``monkey:`` shouldn't
|
||||
fire a 'legacy heuristic' warning because there's no sensitive field
|
||||
here — the user has nothing to migrate."""
|
||||
with caplog.at_level(logging.WARNING, logger="esphome.__main__"):
|
||||
out = _redact_with_legacy_fallback("monkey: 1234\n")
|
||||
assert "\\033[8m" not in out
|
||||
assert not any("legacy substring" in rec.message for rec in caplog.records)
|
||||
|
||||
|
||||
def test_command_config__invokes_legacy_fallback_when_redacting(
|
||||
tmp_path: Path, capfd: CaptureFixture[str]
|
||||
) -> None:
|
||||
|
||||
Reference in New Issue
Block a user