Opened 6 years ago

Closed 6 years ago

#30468 closed Bug (fixed)

assertHTMLEqual doesn't account for all ASCII whitespace in a class attribute.

Reported by: Jon Dufresne Owned by: nobody
Component: Testing framework Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

From https://html.spec.whatwg.org/#classes

When specified on HTML elements, the class attribute must have a value that is a set of space-separated tokens representing the various classes that the element belongs to.

And "space-separated tokens" is defined as:

https://html.spec.whatwg.org/#set-of-space-separated-tokens

A set of space-separated tokens is a string containing zero or more words (known as tokens) separated by one or more ASCII whitespace, where words consist of any string of one or more characters, none of which are ASCII whitespace.

And "ASCII whitespace" is defined as:

https://infra.spec.whatwg.org/#ascii-whitespace

ASCII whitespace is U+0009 TAB, U+000A LF, U+000C FF, U+000D CR, or U+0020 SPACE.

The current implementation (copied and linked below) only accounts for a single space. Not all consecutive ASCII whitespace.

https://github.com/django/django/blob/48235ba807483fe349d2dc66aaeddc0d03f8b0d4/django/test/html.py#L180-L187

        # Special case handling of 'class' attribute, so that comparisons of DOM
        # instances are not sensitive to ordering of classes.
        attrs = [
            (name, " ".join(sorted(value.split(" "))))
            if name == "class"
            else (name, value)
            for name, value in attrs
        ]

Change History (4)

comment:1 by Jon Dufresne, 6 years ago

Has patch: set

comment:2 by Carlton Gibson, 6 years ago

Triage Stage: UnreviewedAccepted

Yep. Great.

comment:3 by Carlton Gibson, 6 years ago

Triage Stage: AcceptedReady for checkin

comment:4 by Carlton Gibson <carlton.gibson@…>, 6 years ago

Resolution: fixed
Status: newclosed

In b7a33ee4:

Fixed #30468 -- Fixed assertHTMLEqual() to handle all ASCII whitespace in a class attribute.

Note: See TracTickets for help on using tickets.
Back to Top