From c87a06238e4ad5d3225b0847018a9967a4ea6b74 Mon Sep 17 00:00:00 2001 From: Eric Ihli Date: Tue, 25 Apr 2023 12:33:06 -0700 Subject: [PATCH] Fix scanner to ignore trailing tabs --- lib/yaml/scanner.py | 10 ++++++++++ tests/data/trailing-tab.code | 1 + tests/data/trailing-tab.data | 2 ++ 3 files changed, 13 insertions(+) create mode 100644 tests/data/trailing-tab.code create mode 100644 tests/data/trailing-tab.data diff --git a/lib/yaml/scanner.py b/lib/yaml/scanner.py index de925b07..35621ea5 100644 --- a/lib/yaml/scanner.py +++ b/lib/yaml/scanner.py @@ -749,6 +749,14 @@ def check_plain(self): # Scanners. + def scan_past_tabs_to_newline(self): + i = 0 + while self.peek(i) in ' \t': + i += 1 + if self.peek(i) in '\0\r\n\x86\u2028\u2029': + self.forward(i) + + def scan_to_next_token(self): # We ignore spaces, line breaks and comments. # If we find a line break in the block context, we set the flag @@ -775,6 +783,8 @@ def scan_to_next_token(self): while not found: while self.peek() == ' ': self.forward() + if self.peek() == '\t': + self.scan_past_tabs_to_newline() if self.peek() == '#': while self.peek() not in '\0\r\n\x85\u2028\u2029': self.forward() diff --git a/tests/data/trailing-tab.code b/tests/data/trailing-tab.code new file mode 100644 index 00000000..44bcba58 --- /dev/null +++ b/tests/data/trailing-tab.code @@ -0,0 +1 @@ +{"foo": ["bar"]} diff --git a/tests/data/trailing-tab.data b/tests/data/trailing-tab.data new file mode 100644 index 00000000..6337bc97 --- /dev/null +++ b/tests/data/trailing-tab.data @@ -0,0 +1,2 @@ +foo: + - bar