Commits

Kirill Simonov committed 8a8091b

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"
}}}

Comments (0)

Files changed (4)

lib/yaml/reader.py

             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':

lib/yaml/scanner.py

             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?
         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.
 
                             "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
 

tests/data/fetch-complex-value-bug.loader-error

+? "foo"
+ : "bar"

tests/data/remove-possible-simple-key-bug.loader-error

+foo: &A bar
+*A ]    # The ']' indicator triggers remove_possible_simple_key,
+        # which should raise an error.
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.