Skip to content

Commit

Permalink
Revert "Allow colon in a plain scalar in a flow context (yaml#45)"
Browse files Browse the repository at this point in the history
This reverts commit c5b135f.
  • Loading branch information
asomov committed Mar 2, 2018
1 parent 298e079 commit d6e157b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
16 changes: 11 additions & 5 deletions lib/yaml/scanner.py
Expand Up @@ -1272,7 +1272,7 @@ def scan_flow_scalar_breaks(self, double, start_mark):
def scan_plain(self):
# See the specification for details.
# We add an additional restriction for the flow context:
# plain scalars in the flow context cannot contain ',' or '?'.
# plain scalars in the flow context cannot contain ',', ':' and '?'.
# We also keep track of the `allow_simple_key` flag here.
# Indentation rules are loosed for the flow context.
chunks = []
Expand All @@ -1291,12 +1291,18 @@ def scan_plain(self):
while True:
ch = self.peek(length)
if ch in u'\0 \t\r\n\x85\u2028\u2029' \
or (ch == u':' and
self.peek(length+1) in u'\0 \t\r\n\x85\u2028\u2029'
+ (u',[]{}' if self.flow_level else u''))\
or (self.flow_level and ch in u',?[]{}'):
or (not self.flow_level and ch == u':' and
self.peek(length+1) in u'\0 \t\r\n\x85\u2028\u2029') \
or (self.flow_level and ch in u',:?[]{}'):
break
length += 1
# It's not clear what we should do with ':' in the flow context.
if (self.flow_level and ch == u':'
and self.peek(length+1) not in u'\0 \t\r\n\x85\u2028\u2029,[]{}'):
self.forward(length)
raise ScannerError("while scanning a plain scalar", start_mark,
"found unexpected ':'", self.get_mark(),
"Please check http://pyyaml.org/wiki/YAMLColonInFlowContext for details.")
if length == 0:
break
self.allow_simple_key = False
Expand Down
16 changes: 11 additions & 5 deletions lib3/yaml/scanner.py
Expand Up @@ -1266,7 +1266,7 @@ def scan_flow_scalar_breaks(self, double, start_mark):
def scan_plain(self):
# See the specification for details.
# We add an additional restriction for the flow context:
# plain scalars in the flow context cannot contain ',' or '?'.
# plain scalars in the flow context cannot contain ',', ':' and '?'.
# We also keep track of the `allow_simple_key` flag here.
# Indentation rules are loosed for the flow context.
chunks = []
Expand All @@ -1285,12 +1285,18 @@ def scan_plain(self):
while True:
ch = self.peek(length)
if ch in '\0 \t\r\n\x85\u2028\u2029' \
or (ch == ':' and
self.peek(length+1) in '\0 \t\r\n\x85\u2028\u2029'
+ (u',[]{}' if self.flow_level else u''))\
or (self.flow_level and ch in ',?[]{}'):
or (not self.flow_level and ch == ':' and
self.peek(length+1) in '\0 \t\r\n\x85\u2028\u2029') \
or (self.flow_level and ch in ',:?[]{}'):
break
length += 1
# It's not clear what we should do with ':' in the flow context.
if (self.flow_level and ch == ':'
and self.peek(length+1) not in '\0 \t\r\n\x85\u2028\u2029,[]{}'):
self.forward(length)
raise ScannerError("while scanning a plain scalar", start_mark,
"found unexpected ':'", self.get_mark(),
"Please check http://pyyaml.org/wiki/YAMLColonInFlowContext for details.")
if length == 0:
break
self.allow_simple_key = False
Expand Down
1 change: 1 addition & 0 deletions tests/data/colon-in-flow-context.loader-error
@@ -0,0 +1 @@
{ foo:bar }

0 comments on commit d6e157b

Please sign in to comment.