From 8d87bb4d91ed732bc08bd39ce114bdcca63abf68 Mon Sep 17 00:00:00 2001 From: Marcel Date: Wed, 30 Nov 2022 17:21:09 +0100 Subject: [PATCH] [parsing] unify tag nesting --- test/test_parsing.py | 6 +++--- yt_dlp/parsing.py | 5 ++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/test/test_parsing.py b/test/test_parsing.py index 8a36beda44..a7e7ec7d46 100644 --- a/test/test_parsing.py +++ b/test/test_parsing.py @@ -325,9 +325,9 @@ def test_tag_return_order(self): str(tags), str([ [Tag('t0'), [Tag('t1'), - [Tag('t2'), Tag('t3'), Tag('t4')]], - [Tag('t5'), Tag('t6')]], - [Tag('t7'), Tag('t8')]])) + [Tag('t2'), [Tag('t3')], [Tag('t4')]]], + [Tag('t5'), [Tag('t6')]]], + [Tag('t7'), [Tag('t8')]]])) def test_html_ignored_ranges(self): def mark_comments(_string, char='^', nochar='-'): diff --git a/yt_dlp/parsing.py b/yt_dlp/parsing.py index 1db6704dd2..c6748d2d8f 100644 --- a/yt_dlp/parsing.py +++ b/yt_dlp/parsing.py @@ -174,12 +174,11 @@ def handle_starttag(self, tag, attrs): if self.predicate(tag, attrs): tag_obj = self.Tag(tag, string=self.rawdata, attrs=attrs) tag_obj.openrange(self._offset, len(tag_text)) + nesting = [tag_obj] + self._nestedtags[-1].append(nesting) if tag_is_open: - nesting = [tag_obj] - self._nestedtags[-1].append(nesting) self._nestedtags.append(nesting) else: - self._nestedtags[-1].append(tag_obj) self.callback(tag_obj) if tag_is_open: self.tagstack.appendleft(tag_obj)