Masterminds / Masterminds/html5-php

non boolean attributes

Open
#184 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
HTML
Stars
1.8k
Forks
122
PR merge metrics
No merged PRs in 30d

Description

disable_html_ns was added to handle non-namespace aware tools. A common example in many usages of this lib:

XPath expressions will always fail because, e.g. xmlns:p != p

The problem with this config option:
Rules are defined for non-Boolean attributes to be output with ="" but these do not kick in when the disable_html_ns option is set.

https://github.com/Masterminds/html5-php/blob/c24cd7e31e02ccf25484bda9ea674b11b5898904/src/HTML5/Serializer/OutputRules.php#L371

What does the spec say?
Earlier versions of the HTML5 spec permitted the empty attribute syntax only for Boolean attributes. Later versions still don’t explicitly state that it is allowed for non-Boolean attributes, but they no longer say it is not (the specific clause, “This syntax is permitted only for boolean attributes,” has been removed).

validator.nu shows both <input disabled> and <input disabled=""> are valid (without namespace declarations).

Suggested changes

  1. A config option to bypass the namespace tests and return return for anything listed in the OutputRules::nonBooleanAttributes

  2. Based on the spec, the list if back to front. It should be listing attributes known as Boolean, rather than the other way round. Any unknown attribute should be classified as non-Boolean.


Item 1 above should be very simple to add and fully BC. Would you accept a PR for that?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/HTML5/Serializer/OutputRules.php around line 371 and trace how disable_html_ns affects non-Boolean attributes. Check the configuration path for adding the proposed namespace-test bypass. Done means the option is backward-compatible and allows listed non-Boolean attributes to serialize with an empty value when namespace handling is disabled.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
web-dev
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.