Skip to content

Commit 8aacb33

Browse files
authored
Merge pull request #10504 from AA-Turner/fix-kbd-findall
Fix `findall` usage in `KeyboardTransform`
2 parents 28f9ce7 + efdbe06 commit 8aacb33

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

sphinx/builders/html/transforms.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ class KeyboardTransform(SphinxPostTransform):
4040

4141
def run(self, **kwargs: Any) -> None:
4242
matcher = NodeMatcher(nodes.literal, classes=["kbd"])
43-
for node in self.document.findall(matcher): # type: nodes.literal
43+
# this list must be pre-created as during iteration new nodes
44+
# are added which match the condition in the NodeMatcher.
45+
for node in list(self.document.findall(matcher)): # type: nodes.literal
4446
parts = self.pattern.split(node[-1].astext())
4547
if len(parts) == 1 or self.is_multiwords_key(parts):
4648
continue

tests/roots/test-transforms-post_transforms-keyboard/conf.py

Whitespace-only changes.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Regression test for issue 10495
2+
===============================
3+
4+
:kbd:`spanish - inquisition`

tests/test_transforms_post_transforms.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,12 @@ def missing_reference(app, env, node, contnode):
4848

4949
content = (app.outdir / 'index.html').read_text(encoding='utf8')
5050
assert '<span class="n"><span class="pre">Age</span></span>' in content
51+
52+
53+
@pytest.mark.sphinx('html', testroot='transforms-post_transforms-keyboard',
54+
freshenv=True)
55+
def test_keyboard_hyphen_spaces(app):
56+
"""Regression test for issue 10495, we want no crash."""
57+
app.build()
58+
assert "spanish" in (app.outdir / 'index.html').read_text(encoding='utf8')
59+
assert "inquisition" in (app.outdir / 'index.html').read_text(encoding='utf8')

0 commit comments

Comments
 (0)