Skip to content

Commit 8e5a423

Browse files
committed
Ensure that get_qualified_attribute_name works with virtual tokens
1 parent 026c3c2 commit 8e5a423

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed

src/wp-includes/html-api/class-wp-html-processor.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5306,6 +5306,25 @@ public function get_attribute( $name ) {
53065306
return parent::get_attribute( $name );
53075307
}
53085308

5309+
/**
5310+
* Returns the adjusted attribute name for a given attribute, taking into
5311+
* account the current parsing context, whether HTML, SVG, or MathML.
5312+
*
5313+
* @since 6.8.0 Subclassed for the HTML Processor.
5314+
*
5315+
* @param string $attribute_name Which attribute name to adjust.
5316+
*
5317+
* @return string|null The qualified attribute name or null if not on matched tag.
5318+
*/
5319+
public function get_qualified_attribute_name( $attribute_name ): ?string {
5320+
if ( $this->is_virtual() ) {
5321+
$namespace = $this->current_element->token->namespace;
5322+
return self::lookup_qualified_attribute_name( $namespace, $attribute_name );
5323+
}
5324+
5325+
return parent::get_qualified_attribute_name( $attribute_name );
5326+
}
5327+
53095328
/**
53105329
* Updates or creates a new attribute on the currently matched tag with the passed value.
53115330
*

src/wp-includes/html-api/class-wp-html-tag-processor.php

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2979,22 +2979,37 @@ public function get_qualified_tag_name(): ?string {
29792979
*
29802980
* @since 6.7.0
29812981
*
2982-
* @param string $attribute_name Which attribute to adjust.
2983-
* @return string|null
2982+
* @param string $attribute_name Which attribute name to adjust.
2983+
*
2984+
* @return string|null The qualified attribute name or null if not on matched tag.
29842985
*/
29852986
public function get_qualified_attribute_name( $attribute_name ): ?string {
29862987
if ( self::STATE_MATCHED_TAG !== $this->parser_state ) {
29872988
return null;
29882989
}
2990+
$namespace = $this->get_namespace();
2991+
return self::lookup_qualified_attribute_name( $namespace, $attribute_name );
2992+
}
29892993

2990-
$namespace = $namespace_override ?? $this->get_namespace();
2994+
/**
2995+
* Returns the adjusted attribute name for a given attribute, taking into
2996+
* account the provided namespace.
2997+
*
2998+
* @since 6.8.0
2999+
*
3000+
* @param string $ns The namespace to use: 'html', 'svg', or 'math'.
3001+
* @param string $attribute_name Which attribute to adjust.
3002+
*
3003+
* @return string The qualified attribute name.
3004+
*/
3005+
final protected static function lookup_qualified_attribute_name( string $ns, string $attribute_name ): string {
29913006
$lower_name = strtolower( $attribute_name );
29923007

2993-
if ( 'math' === $namespace && 'definitionurl' === $lower_name ) {
3008+
if ( 'math' === $ns && 'definitionurl' === $lower_name ) {
29943009
return 'definitionURL';
29953010
}
29963011

2997-
if ( 'svg' === $this->get_namespace() ) {
3012+
if ( 'svg' === $ns ) {
29983013
switch ( $lower_name ) {
29993014
case 'attributename':
30003015
return 'attributeName';
@@ -3172,7 +3187,7 @@ public function get_qualified_attribute_name( $attribute_name ): ?string {
31723187
}
31733188
}
31743189

3175-
if ( 'html' !== $namespace ) {
3190+
if ( 'html' !== $ns ) {
31763191
switch ( $lower_name ) {
31773192
case 'xlink:actuate':
31783193
return 'xlink actuate';

0 commit comments

Comments
 (0)