From 97e2210ec9df205a5e99b4cb964b3259ac7a8894 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Verg=C3=A9?= Date: Fri, 15 Jan 2016 18:08:25 +0100 Subject: [PATCH] Don't treat non-importable YAML as syntax error `yaml.load()` exceptions are not necessarily syntax errors. For instance, the following YAML source cannot be `load()`ed into a Python object, but is valid nonetheless: ? - Detroit Tigers - Chicago cubs : - 2001-07-23 ? [ New York Yankees, Atlanta Braves ] : [ 2001-07-02, 2001-08-12, 2001-08-14 ] This commit detects syntax errors from `yaml.parse()` exceptions rather than `yaml.load_all()`. --- tests/rules/test_syntax_error.py | 14 ++++++++++++++ yamllint/__init__.py | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/tests/rules/test_syntax_error.py b/tests/rules/test_syntax_error.py index c5ed79b..db88539 100644 --- a/tests/rules/test_syntax_error.py +++ b/tests/rules/test_syntax_error.py @@ -35,3 +35,17 @@ class YamlLintTestCase(RuleTestCase): '%TAG ! tag:clarkevans.com,2002:\n' 'doc: ument\n' '...\n', None, problem=(3, 1)) + + def test_mapping_between_sequences(self): + # This is valid YAML. See http://www.yaml.org/spec/1.2/spec.html, + # example 2.11 + self.check('---\n' + '? - Detroit Tigers\n' + ' - Chicago cubs\n' + ':\n' + ' - 2001-07-23\n' + '\n' + '? [New York Yankees,\n' + ' Atlanta Braves]\n' + ': [2001-07-02, 2001-08-12,\n' + ' 2001-08-14]\n', None) diff --git a/yamllint/__init__.py b/yamllint/__init__.py index f468e9f..887c840 100644 --- a/yamllint/__init__.py +++ b/yamllint/__init__.py @@ -58,7 +58,7 @@ def get_costemic_problems(buffer, conf): def get_syntax_error(buffer): try: - list(yaml.safe_load_all(buffer)) + list(yaml.parse(buffer)) except yaml.error.MarkedYAMLError as e: problem = LintProblem(e.problem_mark.line + 1, e.problem_mark.column + 1,