summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxi <xi@18f92427-320e-0410-9341-c67f048884a3>2006-06-16 07:23:05 +0000
committerxi <xi@18f92427-320e-0410-9341-c67f048884a3>2006-06-16 07:23:05 +0000
commitf19968770c0630e16bb5066d20031cc815dc14b9 (patch)
treee93fa82ea8ee6590845d295acf6e520d2c622094
parent56375e650705e0cf92f4a947aaee1d8113a6af1e (diff)
downloadpyyaml-f19968770c0630e16bb5066d20031cc815dc14b9.tar.gz
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
-rw-r--r--lib/yaml/reader.py2
-rw-r--r--lib/yaml/scanner.py22
-rw-r--r--tests/data/fetch-complex-value-bug.loader-error2
-rw-r--r--tests/data/remove-possible-simple-key-bug.loader-error3
4 files changed, 21 insertions, 8 deletions
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.