Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

embed, source, track, wbr HTML elements not considered empty #90942

Closed
jnns mannequin opened this issue Feb 18, 2022 · 3 comments
Closed

embed, source, track, wbr HTML elements not considered empty #90942

jnns mannequin opened this issue Feb 18, 2022 · 3 comments
Labels
3.11 only security fixes topic-XML type-feature A feature request or enhancement

Comments

@jnns
Copy link
Mannequin

jnns mannequin commented Feb 18, 2022

BPO 46786
Nosy @scoder, @jnns
PRs
  • bpo-46786: Consider embed, source, track, wbr as empty tags #31406
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2022-02-27.14:26:44.874>
    created_at = <Date 2022-02-18.10:23:19.542>
    labels = ['expert-XML', 'type-feature', '3.11']
    title = 'embed, source, track, wbr HTML elements not considered empty'
    updated_at = <Date 2022-02-27.14:26:44.874>
    user = 'https://github.com/jnns'

    bugs.python.org fields:

    activity = <Date 2022-02-27.14:26:44.874>
    actor = 'scoder'
    assignee = 'none'
    closed = True
    closed_date = <Date 2022-02-27.14:26:44.874>
    closer = 'scoder'
    components = ['XML']
    creation = <Date 2022-02-18.10:23:19.542>
    creator = 'jnns'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 46786
    keywords = ['patch']
    message_count = 3.0
    messages = ['413473', '413707', '414157']
    nosy_count = 3.0
    nosy_names = ['scoder', 'eli.bendersky', 'jnns']
    pr_nums = ['31406']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue46786'
    versions = ['Python 3.11']

    @jnns
    Copy link
    Mannequin Author

    jnns mannequin commented Feb 18, 2022

    According to the WHATWG, the elements area, base, br, col, embed, hr, img, input, link, meta, param, source, track, wbr are void elements that don't need and therefore shouldn't have a closing tag.

    The source view of Firefox 96 shows a warning about an unexpected closing tag 1.

    In Python 3.10.2 xml.etree seems to correctly recognize most of them as such and doesn't generate closing tags when using the .tostring() method. A few elements are serialized with a closing tag (<embed></embed> for example).

    from xml.etree import ElementTree as etree
    
    void_elements = [
        "area", "base","br", "col", "embed", "hr", "img", 
        "input", "link", "meta", "param", "source", "track", "wbr"
    ]
    for el in void_elements:
        el = etree.Element(el)
        print(etree.tostring(el, method="html", encoding="unicode"))
    <area>
    <base>
    <br>
    <col>
    <embed></embed>
    <hr>
    <img>
    <input>
    <link>
    <meta>
    <param>
    <source></source>
    <track></track>
    <wbr></wbr>

    HTML_EMPTY in Lib/xml/etree/ElementTree.py only contains the following entries:

    "area", "base", "basefont", "br", "col", "frame", "hr", "img", "input", "isindex", "link", "meta", "param"

    I suppose "embed", "source", "track" and "wbr" should be added to that list.

    @jnns jnns mannequin added 3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes 3.10 only security fixes 3.11 only security fixes topic-XML type-feature A feature request or enhancement labels Feb 18, 2022
    @scoder
    Copy link
    Contributor

    scoder commented Feb 22, 2022

    Makes sense. That list hasn't been updated in 10 years.

    @scoder scoder removed 3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes 3.10 only security fixes labels Feb 22, 2022
    @scoder
    Copy link
    Contributor

    scoder commented Feb 27, 2022

    New changeset 345572a by Jannis Vajen in branch 'main':
    bpo-46786: Make ElementTree write the HTML tags embed, source, track, wbr as empty tags (GH-31406)
    345572a

    @scoder scoder closed this as completed Feb 27, 2022
    @scoder scoder closed this as completed Feb 27, 2022
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.11 only security fixes topic-XML type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant