-
Notifications
You must be signed in to change notification settings - Fork 0
Add class whitespace doc #37
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
base: trunk
Are you sure you want to change the base?
Changes from all commits
65d7692
029e33d
1f85596
d450ff9
34157b9
a145ba5
887575d
ee6d916
1e3527b
e84c734
2a84233
c0b0168
02ee515
66dc567
8368854
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5474,6 +5474,17 @@ public function get_attribute_names_with_prefix( $prefix ): ?array { | |
| /** | ||
| * Adds a new class name to the currently matched tag. | ||
| * | ||
| * Whitespace in `$class_name` is preserved verbatim. This may result | ||
| * in multiple class names being added to the element's class list. | ||
| * | ||
| * Examples: | ||
| * | ||
| * $p->add_class( 'wp-block' ); | ||
| * // Adds one class: "wp-block". | ||
| * | ||
| * $p->add_class( 'wp-block alignwide' ); | ||
| * // Adds two classes: "wp-block" and "alignwide". | ||
| * | ||
| * @since 6.6.0 Subclassed for the HTML Processor. | ||
| * | ||
| * @param string $class_name The class name to add. | ||
|
|
@@ -5487,6 +5498,7 @@ public function add_class( $class_name ): bool { | |
| * Removes a class name from the currently matched tag. | ||
| * | ||
| * @since 6.6.0 Subclassed for the HTML Processor. | ||
| * @since 7.1.0 Returns false when `$class_name` contains ASCII whitespace. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this new in 7.1.0? I don’t see any change in behavior that would make it start returning |
||
| * | ||
| * @param string $class_name The class name to remove. | ||
| * @return bool Whether the class was set to be removed. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1242,6 +1242,15 @@ public function has_class( $wanted_class ): ?bool { | |
| return null; | ||
| } | ||
|
|
||
| if ( false !== strpbrk( $wanted_class, " \t\f\r\n" ) ) { | ||
| _doing_it_wrong( | ||
| __METHOD__, | ||
| __( 'A class name cannot contain ASCII whitespace.' ), | ||
| '7.1.0' | ||
| ); | ||
| return false; | ||
| } | ||
|
|
||
| $case_insensitive = self::QUIRKS_MODE === $this->compat_mode; | ||
|
|
||
| $wanted_length = strlen( $wanted_class ); | ||
|
|
@@ -4537,6 +4546,17 @@ public function remove_attribute( $name ): bool { | |
| /** | ||
| * Adds a new class name to the currently matched tag. | ||
| * | ||
| * Whitespace in `$class_name` is preserved verbatim. This may result | ||
| * in multiple class names being added to the element's class list. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. another thought is that maybe we should not preserve this, and especially not declare that we are preserving it. a problem here is adding duplicate class names. I’d really like the interface to be raw PHP strings that aren’t decoded, added as a class name with appropriate encoding. we can trivially add as a stepping stone, maybe we break on appropriate whitespace just to we can deduplicate tags.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is a good opportunity to use my PHP extension in normal cases to explore what happens if someone sends a value like
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe I saw something adding multiple class names this way, which prompted my investigation. I'd have to dig around. |
||
| * | ||
| * Examples: | ||
| * | ||
| * $p->add_class( 'wp-block' ); | ||
| * // Adds one class: "wp-block". | ||
| * | ||
| * $p->add_class( 'wp-block alignwide' ); | ||
| * // Adds two classes: "wp-block" and "alignwide". | ||
| * | ||
| * @since 6.2.0 | ||
| * | ||
| * @param string $class_name The class name to add. | ||
|
|
@@ -4580,6 +4600,7 @@ public function add_class( $class_name ): bool { | |
| * Removes a class name from the currently matched tag. | ||
| * | ||
| * @since 6.2.0 | ||
| * @since 7.1.0 Returns false when `$class_name` contains ASCII whitespace. | ||
| * | ||
| * @param string $class_name The class name to remove. | ||
| * @return bool Whether the class was set to be removed. | ||
|
|
@@ -4592,6 +4613,15 @@ public function remove_class( $class_name ): bool { | |
| return false; | ||
| } | ||
|
|
||
| if ( false !== strpbrk( $class_name, " \t\f\r\n" ) ) { | ||
| _doing_it_wrong( | ||
| __METHOD__, | ||
| __( 'A class name cannot contain ASCII whitespace.' ), | ||
| '7.1.0' | ||
| ); | ||
| return false; | ||
| } | ||
|
|
||
| if ( self::QUIRKS_MODE !== $this->compat_mode ) { | ||
| $this->classname_updates[ $class_name ] = self::REMOVE_CLASS; | ||
| return true; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if we started calling
_doing_it_wrong()here and tried to push code away, so that some day we can reject multiple class name updates?