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

HTML API: Add docs and tests about lowercasing in class_list #6920

Conversation

sirreal
Copy link
Member

@sirreal sirreal commented Jun 27, 2024

The class_list method yields class name strings in lower case. This is
intended but undocumented. Document and add tests for this behavior.

Trac ticket: https://core.trac.wordpress.org/ticket/61520


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

The class_list method yields class name strings in lower case. This is
intended but undocumented. Document and add tests for this behavior.
Copy link

github-actions bot commented Jun 27, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props jonsurrell, khokansardar.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copy link

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@itzmekhokan
Copy link

@sirreal changes LGTM.

@sirreal
Copy link
Member Author

sirreal commented Jun 28, 2024

@dmsnell Will you review these documentation changes? These would be good to backport to 6.6.

Revert other documentation tweaks and only include changes to reflect
the ASCII-lowercase behavior.
@sirreal
Copy link
Member Author

sirreal commented Jun 28, 2024

This may not be the best approach. Rather than documenting the specifics of the behavior here, it seems best to audit the class-related methods.

@sirreal sirreal closed this Jun 28, 2024
@sirreal sirreal deleted the html-api/document-test-class_names-lowercasing branch June 28, 2024 19:23
Copy link
Contributor

@dmsnell dmsnell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some notes, but we talked in person and I think it's worth ignoring all I wrote except for historic purposes.

@@ -1694,13 +1694,13 @@ public function has_class( $wanted_class ) {
}

/**
* Generator for a foreach loop to step through each class name for the matched tag.
* Generator that yields each class name for the matched tag.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm. the wording here was carefully chosen to clue people in on how this function is intended to be used. While I understand that yield is technically what's occurring on the low level of PHP details, but do you find that this change better leads people to understand how to use the method?

*
* This generator function is designed to be used inside a "foreach" loop.
* Class names will be lowercased and unique class names will be yielded once.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm really uncomfortable both taking out relevant information for consumers of this method and then adding new kinds of specifications for things that aren't specified.

In particular I've attempted to avoid using the term lower-case and upper-case except where necessary. if you can find some notion in the CSS specification indicating that this is part of what it means to be a CSS class, then I think it's appropriate. I'm far less versed in the CSS spec so I've been reluctant to add constraints that aren't there.

To this end I've favored creating our own term to avoid the ambiguity, which is $comparable_name.

The best I can find is in CSS2 (repeated up through CSS Selectors, Level 4), which states

All CSS syntax is case-insensitive within the ASCII range…

and

All Selector syntax is ASCII case-insensitive…

The most confusing bit, which is what I was referring to earlier when we discussed this, is a note about quirks mode. In 6.6 Class selectors it says:

When matching against a document which is in quirks mode, class names must be matched ASCII case-insensitively; class selectors are otherwise case-sensitive, only matching class names they are identical to.

We obviously can't know about quirks mode in the Tag Processor, and I don't even think we want to, but I think this section is still speaking specifically about the class attribute and not the CSS classes.

Funny thing is, I can't find any mention of what a class is. All I can find in the CSS specifications are discussions about class selectors.

The DOM specification indicates that the classList getter is a token set whose token list object as known as "the element's classes."

It further hearkens back to the CSS spec when saying,

The comparisons for the classes must be done in an ASCII case-insensitive manner if root's node document's mode is "quirks"; otherwise in an identical to manner.

I don't think there's a specification on classList forcing it to be lower-case.
Safari/WebKit seems to do it by happenstance

Hang on, we're continuing this chat in person and you can ignore all this. it's partial and possibly out-dated.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No-Quirks Mode Quirks Mode
Screenshot 2024-06-28 at 1 18 12 PM Screenshot 2024-06-28 at 1 18 36 PM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants