From 9b8ce28d05597470042c49c6b6d9159c412f9e00 Mon Sep 17 00:00:00 2001 From: Jim Knoble Date: Tue, 3 Dec 2024 15:06:09 -0800 Subject: [PATCH] Add repro test case for #700 --- tests/rules/test_quoted_strings.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/rules/test_quoted_strings.py b/tests/rules/test_quoted_strings.py index 1bcb6f8f..8e78275d 100644 --- a/tests/rules/test_quoted_strings.py +++ b/tests/rules/test_quoted_strings.py @@ -16,6 +16,7 @@ from tests.common import RuleTestCase from yamllint import config +from yaml.reader import ReaderError as yaml_reader_ReaderError class QuotedValuesTestCase(RuleTestCase): @@ -475,6 +476,24 @@ def test_only_when_needed_extras(self): '- "foo bar"\n', conf, problem1=(3, 3), problem2=(7, 3), problem3=(11, 3)) + def test_only_when_needed_special_characters(self): + conf = 'quoted-strings: {required: only-when-needed}\n' + self.check('---\n' + 'k1: "\\u001b (double-quoted backslash-escaped special characters are ok)"\n', + conf) + + def test_only_when_needed_special_characters_exceptions(self): + conf = 'quoted-strings: {required: only-when-needed}\n' + yamltext1 = ('---\n' + 'k1: "\u001b (double-quoted unescaped special characters are not ok)"\n') + yamltext2 = ('---\n' + "k1: '\u001b (single-quoted unescaped special characters are not ok)'\n") + yamltext3 = ('---\n' + 'k1: \u001b (unquoted unescaped special characters are not ok)\n') + self.assertRaises(yaml_reader_ReaderError, self.check, yamltext1, conf) + self.assertRaises(yaml_reader_ReaderError, self.check, yamltext2, conf) + self.assertRaises(yaml_reader_ReaderError, self.check, yamltext3, conf) + def test_octal_values(self): conf = 'quoted-strings: {required: true}\n'