Skip to content

Potential bug: implicitly-closed tag lookup only considers a single previous element #3

@jayaddison

Description

@jayaddison

Hi @willforde - I don't know for certain whether this is a bug - it also looks like it could've been a performance-related decision, but either way, I figured it'd be worth asking about.

There's some code at

# If the previous element is what we actually have then the expected element was not
# properly closed so we must close that before closing what we have now
elif len(_elem) >= 2 and _elem[-2].tag == tag:
that detects "unexpected" closing tags (in other words, we've found a closed tag, but it's not for the element currently being processed).

At the moment, that check only inspects the previous element (second-from-last in the element stack/list) for a match.

There aren't many negative side-effects of this as far as I can tell, but it does allow for more text than expected to be gathered into the _data buffer some cases, and I wondered whether the choice of array index check is intentional?

I'll offer a pull request with an example text-handling problem that can occur, and a possible alternative implementation for the previously-opened-tag condition.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions