From 5f60dbae23af7c39dea31597dab119db1116e6ca Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Thu, 16 Mar 2023 16:36:00 +0000 Subject: [PATCH] Avoid runtime exception caused by newer pathspec --- tests/test_config.py | 5 +++++ yamllint/config.py | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/test_config.py b/tests/test_config.py index 8e90246..1e916c6 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -44,6 +44,11 @@ class SimpleConfigTestCase(unittest.TestCase): with self.assertRaises(config.YamlLintConfigError): config.YamlLintConfig('not: valid: yaml') + def test_is_file_ignored_allows_none(self): + c = config.YamlLintConfig('ignore: foobar\n') + self.assertTrue(c.is_file_ignored('foobar')) + self.assertFalse(c.is_file_ignored(None)) + def test_unknown_rule(self): with self.assertRaisesRegex( config.YamlLintConfigError, diff --git a/yamllint/config.py b/yamllint/config.py index a5ef405..285400a 100644 --- a/yamllint/config.py +++ b/yamllint/config.py @@ -45,7 +45,7 @@ class YamlLintConfig: self.validate() def is_file_ignored(self, filepath): - return self.ignore and self.ignore.match_file(filepath) + return self.ignore and filepath and self.ignore.match_file(filepath) def is_yaml_file(self, filepath): return self.yaml_files.match_file(os.path.basename(filepath))