File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed
Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -213,11 +213,26 @@ def _run(self) -> list[MatchError]:
213213
214214 # remove exclusions
215215 for lintable in self .lintables .copy ():
216+ # 1. Standard exclusion check
216217 if self .is_excluded (lintable ):
217218 _logger .debug ("Excluded %s" , lintable )
218219 self .lintables .remove (lintable )
219220 continue
221+
222+ # 2. Handle load errors (This is where SOPS/Broken YAML crashes)
220223 if isinstance (lintable .data , States ) and lintable .exc :
224+ # --- NEW LOGIC FOR #4745 ---
225+ # Even if it's 'explicit', if it's broken, we check the exclude_paths
226+ # one last time before reporting a 'load-failure'.
227+ abs_path = str (lintable .abspath )
228+ if any (
229+ abs_path .startswith (p ) or fnmatch (abs_path , p )
230+ for p in self .exclude_paths
231+ ):
232+ self .lintables .remove (lintable )
233+ continue
234+ # --- END NEW LOGIC ---
235+
221236 line = 1
222237 column = None
223238 detail = ""
Original file line number Diff line number Diff line change @@ -87,6 +87,25 @@ def test_runner_exclude_paths(default_rules_collection: RulesCollection) -> None
8787 assert len (matches ) == 0
8888
8989
90+ def test_exclude_paths_ignores_broken_yaml (
91+ default_rules_collection : RulesCollection ,
92+ tmp_path : Path ,
93+ ) -> None :
94+ """Ensure exclude_paths prevents parsing of invalid YAML files (#4745)."""
95+ broken_yaml = tmp_path / "secrets.yml"
96+ broken_yaml .write_text ("---\n invalid: : : : yaml\n " , encoding = "utf-8" )
97+
98+ runner = Runner (
99+ broken_yaml ,
100+ rules = default_rules_collection ,
101+ exclude_paths = [str (broken_yaml )],
102+ )
103+
104+ results = runner .run ()
105+
106+ assert len (results ) == 0
107+
108+
90109@pytest .mark .parametrize (
91110 ("exclude_path" ),
92111 (pytest .param ("**/playbooks_globs/*b.yml" , id = "1" ),),
You can’t perform that action at this time.
0 commit comments