From f19968770c0630e16bb5066d20031cc815dc14b9 Mon Sep 17 00:00:00 2001 From: xi Date: Fri, 16 Jun 2006 07:23:05 +0000 Subject: [PATCH] Fix several problems caused by ill-formed documents. The line number is not calculated correctly for DOS-style line breaks. Fix error reporting in '''remove_possible_simple_key'''. The problem is caused by the document: {{{ +foo: &A bar +*A ] }}} Raise an error for a complex key which is not indented correctly, for instance: {{{ ? "foo" : "bar" }}} git-svn-id: http://svn.pyyaml.org/pyyaml/trunk@188 18f92427-320e-0410-9341-c67f048884a3 --- lib/yaml/reader.py | 2 +- lib/yaml/scanner.py | 22 +++++++++++++++------- tests/data/fetch-complex-value-bug.loader-error | 2 ++ .../remove-possible-simple-key-bug.loader-error | 3 +++ 4 files changed, 21 insertions(+), 8 deletions(-) create mode 100644 tests/data/fetch-complex-value-bug.loader-error create mode 100644 tests/data/remove-possible-simple-key-bug.loader-error diff --git a/lib/yaml/reader.py b/lib/yaml/reader.py index e9c34b1..9048ea8 100644 --- a/lib/yaml/reader.py +++ b/lib/yaml/reader.py @@ -139,7 +139,7 @@ class Reader: self.pointer += 1 self.index += 1 if ch in u'\n\x85\u2028\u2029' \ - or (ch == u'\r' and self.buffer[self.pointer+1] != u'\n'): + or (ch == u'\r' and self.buffer[self.pointer] != u'\n'): self.line += 1 self.column = 0 elif ch != u'\uFEFF': diff --git a/lib/yaml/scanner.py b/lib/yaml/scanner.py index cf2478f..059b173 100644 --- a/lib/yaml/scanner.py +++ b/lib/yaml/scanner.py @@ -214,11 +214,11 @@ class Scanner: return self.fetch_flow_mapping_end() # Is it the flow entry indicator? - if ch in u',': + if ch == u',': return self.fetch_flow_entry() # Is it the block entry indicator? - if ch in u'-' and self.check_block_entry(): + if ch == u'-' and self.check_block_entry(): return self.fetch_block_entry() # Is it the key indicator? @@ -325,11 +325,11 @@ class Scanner: if self.flow_level in self.possible_simple_keys: key = self.possible_simple_keys[self.flow_level] - # I don't think it's possible, but I could be wrong. - assert not key.required - #if key.required: - # raise ScannerError("while scanning a simple key", key.mark, - # "could not found expected ':'", self.get_mark()) + if key.required: + raise ScannerError("while scanning a simple key", key.mark, + "could not found expected ':'", self.get_mark()) + + del self.possible_simple_keys[self.flow_level] # Indentation functions. @@ -588,6 +588,14 @@ class Scanner: "mapping values are not allowed here", self.get_mark()) + # If this value starts a new block mapping, we need to add + # BLOCK-MAPPING-START. It will be detected as an error later by + # the parser. + if not self.flow_level: + if self.add_indent(self.column): + mark = self.get_mark() + self.tokens.append(BlockMappingStartToken(mark, mark)) + # Simple keys are allowed after ':' in the block context. self.allow_simple_key = not self.flow_level diff --git a/tests/data/fetch-complex-value-bug.loader-error b/tests/data/fetch-complex-value-bug.loader-error new file mode 100644 index 0000000..25fac24 --- /dev/null +++ b/tests/data/fetch-complex-value-bug.loader-error @@ -0,0 +1,2 @@ +? "foo" + : "bar" diff --git a/tests/data/remove-possible-simple-key-bug.loader-error b/tests/data/remove-possible-simple-key-bug.loader-error new file mode 100644 index 0000000..fe1bc6c --- /dev/null +++ b/tests/data/remove-possible-simple-key-bug.loader-error @@ -0,0 +1,3 @@ +foo: &A bar +*A ] # The ']' indicator triggers remove_possible_simple_key, + # which should raise an error. -- 2.11.4.GIT