summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsixolet <naomi@seyfer.org>2018-09-05 16:19:17 -0700
committersixolet <naomi@seyfer.org>2018-09-05 16:19:17 -0700
commitc93735f860031c38616acbff83ce7ce55f30f40f (patch)
tree6b8d7564143815720f03207f3449fad37d8c8d68
parent79195ab05d3f1c4513e8bdd29ad0327612f1ffb5 (diff)
downloadruamel.yaml-c93735f860031c38616acbff83ce7ce55f30f40f.tar.gz
Change an unmatched closing bracket from an IndexError to a ScannerError.
Since it's a problem with the user's document, it should be some kind of YAMLError at least.
-rw-r--r--_test/test_issues.py12
-rw-r--r--scanner.py6
2 files changed, 17 insertions, 1 deletions
diff --git a/_test/test_issues.py b/_test/test_issues.py
index 62c1d92..171eb2b 100644
--- a/_test/test_issues.py
+++ b/_test/test_issues.py
@@ -380,3 +380,15 @@ class TestIssues:
yaml = ruamel.yaml.YAML(typ='safe')
yaml.load('phone: 0123456789')
+
+ def test_issue_232(self):
+ import ruamel.yaml
+ from ruamel import yaml
+ with pytest.raises(ruamel.yaml.scanner.ScannerError, match='unmatched'):
+ yaml.safe_load(']')
+ with pytest.raises(ruamel.yaml.scanner.ScannerError, match='unmatched'):
+ yaml.load(']')
+ with pytest.raises(ruamel.yaml.scanner.ScannerError, match='expected'):
+ yaml.safe_load('{]')
+ with pytest.raises(ruamel.yaml.scanner.ScannerError, match='expected'):
+ yaml.load('{]')
diff --git a/scanner.py b/scanner.py
index 741cda6..b8e9ece 100644
--- a/scanner.py
+++ b/scanner.py
@@ -532,8 +532,12 @@ class Scanner(object):
# Reset possible simple key on the current level.
self.remove_possible_simple_key()
# Decrease the flow level.
+ if not self.flow_context:
+ raise ScannerError(None, None, 'unmatched ending bracket', self.reader.get_mark())
popped = self.flow_context.pop()
- assert popped == to_pop
+ if popped != to_pop:
+ raise ScannerError(None, None, 'expected %s found %s' % (to_pop, popped),
+ self.reader.get_mark())
# No simple keys after ']' or '}'.
self.allow_simple_key = False
# Add FLOW-SEQUENCE-END or FLOW-MAPPING-END.