Skip to content

Fix TypeError for a valueless data-toc-label - #1715

Closed
lidongze1002 wants to merge 1 commit into
Python-Markdown:masterfrom
lidongze1002:fix/valueless-data-toc-label
Closed

lidongze1002 wants to merge 1 commit into
Python-Markdown:masterfrom
lidongze1002:fix/valueless-data-toc-label

Conversation

@lidongze1002

Copy link
Copy Markdown

Description

A heading with a bare data-toc-label attribute crashes the toc extension:

import markdown
markdown.markdown('# Hello {: data-toc-label }', extensions=['toc', 'attr_list'])
# TypeError: expected string or bytes-like object, got 'NoneType'

attr_list stores a bare attribute as None, and TocTreeprocessor.run() hands that value straight to unescape(). #1705 fixed exactly this for a valueless id; this does the same for data-toc-label: a valueless label is treated like a missing one, the heading text becomes the label, and the attribute is dropped so it no longer reaches the output HTML either.

This is a regression: 3.11.2 rendered <h1 id="hello">Hello</h1>, 3.11.3 and master raise.

Test evidence

AI Assistance Disclosure

  • No AI tools were used in preparing this PR.

  • AI tools were used and I have disclosed which ones, and have fully reviewed and verified their output.

    AI tools were used to assist with the following:

    • Code
    • Code Comments
    • Documentation
    • Changelog Entry
    • Commit Message
    • The Description Above
    • Other: ______________

    The tool was OpenCode running DeepSeek V4.1 Flash as the coding agent.

Checklist

The attr_list extension writes a bare attribute with a value of None, and toc
read data-toc-label without allowing for that, so a heading written as
"# Heading {: data-toc-label }" raised TypeError: expected string or
bytes-like object, got 'NoneType' from unescape. A valueless label is no label
at all: the heading text is used and the attribute is dropped, which is how a
valueless id has been handled since Python-Markdown#1705.

Closes Python-Markdown#1712.
@waylan

waylan commented Nov 17, 2026

Copy link
Copy Markdown
Member

I am closing this as a duplicate of #1714.

@waylan waylan closed this Nov 17, 2026
@waylan waylan added the duplicate The issue has been previously reported. label Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

duplicate The issue has been previously reported.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants