- Timestamp:
- 09/25/2023 07:13:27 PM (21 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/6.3/src/wp-includes/html-api/class-wp-html-tag-processor.php
r56564 r56685 406 406 */ 407 407 private $attributes = array(); 408 409 /** 410 * Tracks spans of duplicate attributes on a given tag, used for removing 411 * all copies of an attribute when calling `remove_attribute()`. 412 * 413 * @since 6.3.2 414 * 415 * @var (WP_HTML_Span[])[]|null 416 */ 417 private $duplicate_attributes = null; 408 418 409 419 /** … … 1287 1297 ! $has_value 1288 1298 ); 1299 1300 return true; 1301 } 1302 1303 /* 1304 * Track the duplicate attributes so if we remove it, all disappear together. 1305 * 1306 * While `$this->duplicated_attributes` could always be stored as an `array()`, 1307 * which would simplify the logic here, storing a `null` and only allocating 1308 * an array when encountering duplicates avoids needless allocations in the 1309 * normative case of parsing tags with no duplicate attributes. 1310 */ 1311 $duplicate_span = new WP_HTML_Span( $attribute_start, $attribute_end ); 1312 if ( null === $this->duplicate_attributes ) { 1313 $this->duplicate_attributes = array( $comparable_name => array( $duplicate_span ) ); 1314 } elseif ( ! array_key_exists( $comparable_name, $this->duplicate_attributes ) ) { 1315 $this->duplicate_attributes[ $comparable_name ] = array( $duplicate_span ); 1316 } else { 1317 $this->duplicate_attributes[ $comparable_name ][] = $duplicate_span; 1289 1318 } 1290 1319 … … 1308 1337 private function after_tag() { 1309 1338 $this->get_updated_html(); 1310 $this->tag_name_starts_at = null; 1311 $this->tag_name_length = null; 1312 $this->tag_ends_at = null; 1313 $this->is_closing_tag = null; 1314 $this->attributes = array(); 1339 $this->tag_name_starts_at = null; 1340 $this->tag_name_length = null; 1341 $this->tag_ends_at = null; 1342 $this->is_closing_tag = null; 1343 $this->attributes = array(); 1344 $this->duplicate_attributes = null; 1315 1345 } 1316 1346 … … 2081 2111 ); 2082 2112 2113 // Removes any duplicated attributes if they were also present. 2114 if ( null !== $this->duplicate_attributes && array_key_exists( $name, $this->duplicate_attributes ) ) { 2115 foreach ( $this->duplicate_attributes[ $name ] as $attribute_token ) { 2116 $this->lexical_updates[] = new WP_HTML_Text_Replacement( 2117 $attribute_token->start, 2118 $attribute_token->end, 2119 '' 2120 ); 2121 } 2122 } 2123 2083 2124 return true; 2084 2125 }
Note: See TracChangeset
for help on using the changeset viewer.