From 3fd8abb2d0d241520bd1a915f659886dc1d37d56 Mon Sep 17 00:00:00 2001 From: Ken Kundert Date: Sat, 18 May 2024 19:38:59 -0700 Subject: [PATCH] raise error if there is extra content beyond top data --- nestedtext/nestedtext.py | 16 ++++++++-------- tests/official_tests | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/nestedtext/nestedtext.py b/nestedtext/nestedtext.py index cbea9d3..5691613 100644 --- a/nestedtext/nestedtext.py +++ b/nestedtext/nestedtext.py @@ -911,9 +911,8 @@ def __init__(self, lines, top, source, on_dup, keymap, normalize_key, dialect): self.values, self.keymap = None, None else: self.values, self.keymap = self._read_value(0, ()) - return - if top in ["dict", dict]: + elif top in ["dict", dict]: if next_is in ["dict item", "key item", "inline dict"]: self.values, self.keymap = self._read_value(0, ()) elif next_is is None: @@ -923,9 +922,8 @@ def __init__(self, lines, top, source, on_dup, keymap, normalize_key, dialect): "content must start with key or brace ({{).", lines.get_next() ) - return - if top in ["list", list]: + elif top in ["list", list]: if next_is in ["list item", "inline list"]: self.values, self.keymap = self._read_value(0, ()) elif next_is is None: @@ -935,9 +933,8 @@ def __init__(self, lines, top, source, on_dup, keymap, normalize_key, dialect): "content must start with dash (-) or bracket ([).", lines.get_next(), ) - return - if top in ["str", str]: + elif top in ["str", str]: if next_is == "string item": self.values, self.keymap = self._read_value(0, ()) elif next_is is None: @@ -947,9 +944,12 @@ def __init__(self, lines, top, source, on_dup, keymap, normalize_key, dialect): "content must start with greater-than sign (>).", lines.get_next(), ) - return - raise NotImplementedError(top) + else: + raise NotImplementedError(top) + + if lines.type_of_next(): + report('extra content', lines.get_next()) # get_decoded() {{{3 def get_decoded(self): diff --git a/tests/official_tests b/tests/official_tests index 2182a66..72f9554 160000 --- a/tests/official_tests +++ b/tests/official_tests @@ -1 +1 @@ -Subproject commit 2182a660ffcbbbcff7953e13c8b9b87f14e05998 +Subproject commit 72f955405e3058143aa5dce968d02f8661f260f4