Html::getId is outdated and has a few bugs as well

Created on 15 October 2020, over 3 years ago
Updated 30 January 2023, over 1 year ago

Problem/Motivation

Drupal\Component\Utility\Html::getId cites the HTML4 standard but Drupal 8 is HTML 5 (yay!). HTML 5 is much more permissive https://mathiasbynens.be/notes/html5-id-class Even IE11 is on board.

However the CSS spec cited by the method disallows certain combinations at the beginning of the string which are not filtered out.

Steps to reproduce

Proposed resolution

Implement the full CSS2.1 requirements, HTML 5 will be covered.

  1. Permit characters above 00A0
  2. Remove disallowed starting combinations

There are BC concerns. Maybe we should add a new ModernHtml class and class_alias it from default.settings.php so only new installs get the new code automatically and anyone who needs it can copy it manually but existing sites see no ID changes.

Remaining tasks

Agree then test.

User interface changes

API changes

Data model changes

Release notes snippet

πŸ› Bug report
Status

Needs work

Version

10.1 ✨

Component
BaseΒ  β†’

Last updated about 2 hours ago

Created by

πŸ‡¨πŸ‡¦Canada Charlie ChX Negyesi 🍁Canada

Live updates comments and jobs are added and updated live.
  • Needs release manager review

    It is used to alert the release manager core committer(s) that an issue significantly affects the overall technical debt or release timeline of Drupal, and their signoff is needed. See the governance policy draft for more information.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡¬πŸ‡§United Kingdom catch

    #9 doesn't remove the bc considerations - if there are contrib or custom modules relying on HTML IDs (they shouldn't), then they would potentially need to handle both versions then.

    I think I would probably go back to #7 here and just make the change with a release note and change record. Leaving the RM review tag on to get a second opinion.

  • πŸ‡ΊπŸ‡ΈUnited States bnjmnm Ann Arbor, MI

    No BC concerns the id requirements for HTML5 are more permissive. Any id supported by earlier HTML specs will continue to work in HTML 5.

    Similarly, the additional CSS 2.1 id criteria being checked for in the new method does not introduce anything that isn't already disallowed by the HTML4 spec.

  • Status changed to Needs work over 1 year ago
  • The Needs Review Queue Bot β†’ tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

    Consult the Drupal Contributor Guide β†’ to find step-by-step guides for working with issues.

Production build 0.69.0 2024