summaryrefslogtreecommitdiff
path: root/bs4
diff options
context:
space:
mode:
authorLeonard Richardson <leonardr@segfault.org>2023-03-24 14:50:39 -0400
committerLeonard Richardson <leonardr@segfault.org>2023-03-24 14:50:39 -0400
commitf834cd013865febdff3952b01bdd09b406c8ca66 (patch)
tree4368dc72e39574fddeffd701b40b7f8cd9ffff3c /bs4
parent2236d4acae21d9c5595924902134e5072648c29c (diff)
Added a test just to verify that you can encode a document more deeply nested than the Python recursion limit.
Diffstat (limited to 'bs4')
-rw-r--r--bs4/tests/test_pageelement.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/bs4/tests/test_pageelement.py b/bs4/tests/test_pageelement.py
index a0476e4..d98c577 100644
--- a/bs4/tests/test_pageelement.py
+++ b/bs4/tests/test_pageelement.py
@@ -2,6 +2,7 @@
import copy
import pickle
import pytest
+import sys
from bs4 import BeautifulSoup
from bs4.element import (
@@ -49,6 +50,16 @@ class TestEncoding(SoupTest):
encoding="utf8"
)
+ def test_encode_deeply_nested_document(self):
+ # This test verifies that encoding a string doesn't involve
+ # any recursive function calls. If it did, this test would
+ # overflow the Python interpreter stack.
+ limit = sys.getrecursionlimit() + 1
+ markup = "<span>" * limit
+ soup = self.soup(markup)
+ encoded = soup.encode()
+ assert limit == encoded.count(b"<span>")
+
def test_deprecated_renderContents(self):
html = "<b>\N{SNOWMAN}</b>"
soup = self.soup(html)