From 91f38ed27579d06d8d500662b5aa8386b01d9f08 Mon Sep 17 00:00:00 2001 From: Daniel Beer Date: Wed, 7 Dec 2016 14:06:41 -0500 Subject: [PATCH 1/2] Allow colon in a plain scalar in a flow context --- lib/yaml/scanner.py | 13 +++---------- lib3/yaml/scanner.py | 13 +++---------- tests/data/colon-in-flow-context.loader-error | 1 - tests/data/spec-08-13.canonical | 2 +- 4 files changed, 7 insertions(+), 22 deletions(-) delete mode 100644 tests/data/colon-in-flow-context.loader-error diff --git a/lib/yaml/scanner.py b/lib/yaml/scanner.py index 834f662a..6d2671a5 100644 --- a/lib/yaml/scanner.py +++ b/lib/yaml/scanner.py @@ -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 ',', ':' and '?'. + # plain scalars in the flow context cannot contain ',' or '?'. # We also keep track of the `allow_simple_key` flag here. # Indentation rules are loosed for the flow context. chunks = [] @@ -1291,18 +1291,11 @@ def scan_plain(self): while True: ch = self.peek(length) if ch in u'\0 \t\r\n\x85\u2028\u2029' \ - or (not self.flow_level and ch == u':' and + or (ch == u':' and self.peek(length+1) in u'\0 \t\r\n\x85\u2028\u2029') \ - or (self.flow_level and ch in u',:?[]{}'): + 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 diff --git a/lib3/yaml/scanner.py b/lib3/yaml/scanner.py index c8d127b8..85fec700 100644 --- a/lib3/yaml/scanner.py +++ b/lib3/yaml/scanner.py @@ -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 ',', ':' and '?'. + # plain scalars in the flow context cannot contain ',' or '?'. # We also keep track of the `allow_simple_key` flag here. # Indentation rules are loosed for the flow context. chunks = [] @@ -1285,18 +1285,11 @@ def scan_plain(self): while True: ch = self.peek(length) if ch in '\0 \t\r\n\x85\u2028\u2029' \ - or (not self.flow_level and ch == ':' and + or (ch == ':' and self.peek(length+1) in '\0 \t\r\n\x85\u2028\u2029') \ - or (self.flow_level and ch in ',:?[]{}'): + 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 diff --git a/tests/data/colon-in-flow-context.loader-error b/tests/data/colon-in-flow-context.loader-error deleted file mode 100644 index 13d50875..00000000 --- a/tests/data/colon-in-flow-context.loader-error +++ /dev/null @@ -1 +0,0 @@ -{ foo:bar } diff --git a/tests/data/spec-08-13.canonical b/tests/data/spec-08-13.canonical index 618bb7bd..8f08fe3d 100644 --- a/tests/data/spec-08-13.canonical +++ b/tests/data/spec-08-13.canonical @@ -1,7 +1,7 @@ %YAML 1.1 --- !!map { - ? !!str "foo" + ? !!str "foo :" # : !!str "", # ? !!str "" : !!null "", From 53e22adde61c95d3e7160838025783ecedcec2c7 Mon Sep 17 00:00:00 2001 From: Daniel Beer Date: Thu, 8 Dec 2016 16:08:30 -0500 Subject: [PATCH 2/2] Restore behavior of flow mapping with empty value --- lib/yaml/scanner.py | 3 ++- lib3/yaml/scanner.py | 3 ++- tests/data/spec-08-13.canonical | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/yaml/scanner.py b/lib/yaml/scanner.py index 6d2671a5..73a31774 100644 --- a/lib/yaml/scanner.py +++ b/lib/yaml/scanner.py @@ -1292,7 +1292,8 @@ def scan_plain(self): 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') \ + 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',?[]{}'): break length += 1 diff --git a/lib3/yaml/scanner.py b/lib3/yaml/scanner.py index 85fec700..172c788c 100644 --- a/lib3/yaml/scanner.py +++ b/lib3/yaml/scanner.py @@ -1286,7 +1286,8 @@ def scan_plain(self): 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') \ + 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 ',?[]{}'): break length += 1 diff --git a/tests/data/spec-08-13.canonical b/tests/data/spec-08-13.canonical index 8f08fe3d..618bb7bd 100644 --- a/tests/data/spec-08-13.canonical +++ b/tests/data/spec-08-13.canonical @@ -1,7 +1,7 @@ %YAML 1.1 --- !!map { - ? !!str "foo :" + ? !!str "foo" # : !!str "", # ? !!str "" : !!null "",