Skip to content

Commit c6d69e1

Browse files
committed
HTML API: Backport updates from Core
1 parent 1d724fa commit c6d69e1

File tree

2 files changed

+32
-26
lines changed

2 files changed

+32
-26
lines changed

lib/compat/wordpress-6.2/html-api/class-wp-html-tag-processor.php

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
* Example:
4141
* ```php
4242
* $tags = new WP_HTML_Tag_Processor( $html );
43-
* if ( $tags->next_tag( array( 'tag_name' => 'option' ) ) ) {
43+
* if ( $tags->next_tag( 'option' ) ) {
4444
* $tags->set_attribute( 'selected', true );
4545
* }
4646
* ```
@@ -58,10 +58,11 @@
5858
* $tags->next_tag();
5959
* ```
6060
*
61-
* | Goal | Query |
62-
* |-----------------------------------------------------------|----------------------------------------------------------------------------|
63-
* | Find any tag. | `$tags->next_tag();` |
61+
* | Goal | Query |
62+
* |-----------------------------------------------------------|---------------------------------------------------------------------------------|
63+
* | Find any tag. | `$tags->next_tag();` |
6464
* | Find next image tag. | `$tags->next_tag( array( 'tag_name' => 'img' ) );` |
65+
* | Find next image tag (without passing the array). | `$tags->next_tag( 'img' );` |
6566
* | Find next tag containing the `fullwidth` CSS class. | `$tags->next_tag( array( 'class_name' => 'fullwidth' ) );` |
6667
* | Find next image tag containing the `fullwidth` CSS class. | `$tags->next_tag( array( 'tag_name' => 'img', 'class_name' => 'fullwidth' ) );` |
6768
*
@@ -775,7 +776,8 @@ private function skip_rcdata( $tag_name ) {
775776
return false;
776777
}
777778

778-
$at += 2;
779+
$closer_potentially_starts_at = $at;
780+
$at += 2;
779781

780782
/*
781783
* Find a case-insensitive match to the tag name.
@@ -818,7 +820,7 @@ private function skip_rcdata( $tag_name ) {
818820
}
819821

820822
if ( '>' === $html[ $at ] || '/' === $html[ $at ] ) {
821-
++$this->bytes_already_parsed;
823+
$this->bytes_already_parsed = $closer_potentially_starts_at;
822824
return true;
823825
}
824826
}
@@ -887,7 +889,8 @@ private function skip_script_data() {
887889
}
888890

889891
if ( '/' === $html[ $at ] ) {
890-
$is_closing = true;
892+
$closer_potentially_starts_at = $at - 1;
893+
$is_closing = true;
891894
++$at;
892895
} else {
893896
$is_closing = false;
@@ -938,7 +941,7 @@ private function skip_script_data() {
938941
}
939942

940943
if ( $is_closing ) {
941-
$this->bytes_already_parsed = $at;
944+
$this->bytes_already_parsed = $closer_potentially_starts_at;
942945
if ( $this->bytes_already_parsed >= $doc_length ) {
943946
return false;
944947
}
@@ -948,7 +951,7 @@ private function skip_script_data() {
948951
}
949952

950953
if ( '>' === $html[ $this->bytes_already_parsed ] ) {
951-
++$this->bytes_already_parsed;
954+
$this->bytes_already_parsed = $closer_potentially_starts_at;
952955
return true;
953956
}
954957
}
@@ -1608,7 +1611,7 @@ private function get_enqueued_attribute_value( $comparable_name ) {
16081611
* $p->get_attribute( 'enabled' ) === true;
16091612
* $p->get_attribute( 'aria-label' ) === null;
16101613
*
1611-
* $p->next_tag( array() ) === false;
1614+
* $p->next_tag() === false;
16121615
* $p->get_attribute( 'class' ) === null;
16131616
* ```
16141617
*
@@ -1689,7 +1692,7 @@ public function get_attribute( $name ) {
16891692
* $p->next_tag( array( 'class_name' => 'test' ) ) === true;
16901693
* $p->get_attribute_names_with_prefix( 'data-' ) === array( 'data-enabled', 'data-test-id' );
16911694
*
1692-
* $p->next_tag( array() ) === false;
1695+
* $p->next_tag() === false;
16931696
* $p->get_attribute_names_with_prefix( 'data-' ) === null;
16941697
* ```
16951698
*
@@ -1720,10 +1723,10 @@ function get_attribute_names_with_prefix( $prefix ) {
17201723
* Example:
17211724
* ```php
17221725
* $p = new WP_HTML_Tag_Processor( '<DIV CLASS="test">Test</DIV>' );
1723-
* $p->next_tag( array() ) === true;
1726+
* $p->next_tag() === true;
17241727
* $p->get_tag() === 'DIV';
17251728
*
1726-
* $p->next_tag( array() ) === false;
1729+
* $p->next_tag() === false;
17271730
* $p->get_tag() === null;
17281731
* ```
17291732
*

lib/compat/wordpress-6.3/html-api/class-gutenberg-html-tag-processor-6-3.php

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
* Example:
4141
* ```php
4242
* $tags = new WP_HTML_Tag_Processor( $html );
43-
* if ( $tags->next_tag( array( 'tag_name' => 'option' ) ) ) {
43+
* if ( $tags->next_tag( 'option' ) ) {
4444
* $tags->set_attribute( 'selected', true );
4545
* }
4646
* ```
@@ -58,10 +58,11 @@
5858
* $tags->next_tag();
5959
* ```
6060
*
61-
* | Goal | Query |
62-
* |-----------------------------------------------------------|----------------------------------------------------------------------------|
63-
* | Find any tag. | `$tags->next_tag();` |
61+
* | Goal | Query |
62+
* |-----------------------------------------------------------|---------------------------------------------------------------------------------|
63+
* | Find any tag. | `$tags->next_tag();` |
6464
* | Find next image tag. | `$tags->next_tag( array( 'tag_name' => 'img' ) );` |
65+
* | Find next image tag (without passing the array). | `$tags->next_tag( 'img' );` |
6566
* | Find next tag containing the `fullwidth` CSS class. | `$tags->next_tag( array( 'class_name' => 'fullwidth' ) );` |
6667
* | Find next image tag containing the `fullwidth` CSS class. | `$tags->next_tag( array( 'tag_name' => 'img', 'class_name' => 'fullwidth' ) );` |
6768
*
@@ -775,7 +776,8 @@ private function skip_rcdata( $tag_name ) {
775776
return false;
776777
}
777778

778-
$at += 2;
779+
$closer_potentially_starts_at = $at;
780+
$at += 2;
779781

780782
/*
781783
* Find a case-insensitive match to the tag name.
@@ -818,7 +820,7 @@ private function skip_rcdata( $tag_name ) {
818820
}
819821

820822
if ( '>' === $html[ $at ] || '/' === $html[ $at ] ) {
821-
++$this->bytes_already_parsed;
823+
$this->bytes_already_parsed = $closer_potentially_starts_at;
822824
return true;
823825
}
824826
}
@@ -887,7 +889,8 @@ private function skip_script_data() {
887889
}
888890

889891
if ( '/' === $html[ $at ] ) {
890-
$is_closing = true;
892+
$closer_potentially_starts_at = $at - 1;
893+
$is_closing = true;
891894
++$at;
892895
} else {
893896
$is_closing = false;
@@ -938,7 +941,7 @@ private function skip_script_data() {
938941
}
939942

940943
if ( $is_closing ) {
941-
$this->bytes_already_parsed = $at;
944+
$this->bytes_already_parsed = $closer_potentially_starts_at;
942945
if ( $this->bytes_already_parsed >= $doc_length ) {
943946
return false;
944947
}
@@ -948,7 +951,7 @@ private function skip_script_data() {
948951
}
949952

950953
if ( '>' === $html[ $this->bytes_already_parsed ] ) {
951-
++$this->bytes_already_parsed;
954+
$this->bytes_already_parsed = $closer_potentially_starts_at;
952955
return true;
953956
}
954957
}
@@ -1623,7 +1626,7 @@ private function get_enqueued_attribute_value( $comparable_name ) {
16231626
* $p->get_attribute( 'enabled' ) === true;
16241627
* $p->get_attribute( 'aria-label' ) === null;
16251628
*
1626-
* $p->next_tag( array() ) === false;
1629+
* $p->next_tag() === false;
16271630
* $p->get_attribute( 'class' ) === null;
16281631
* ```
16291632
*
@@ -1704,7 +1707,7 @@ public function get_attribute( $name ) {
17041707
* $p->next_tag( array( 'class_name' => 'test' ) ) === true;
17051708
* $p->get_attribute_names_with_prefix( 'data-' ) === array( 'data-enabled', 'data-test-id' );
17061709
*
1707-
* $p->next_tag( array() ) === false;
1710+
* $p->next_tag() === false;
17081711
* $p->get_attribute_names_with_prefix( 'data-' ) === null;
17091712
* ```
17101713
*
@@ -1735,10 +1738,10 @@ function get_attribute_names_with_prefix( $prefix ) {
17351738
* Example:
17361739
* ```php
17371740
* $p = new WP_HTML_Tag_Processor( '<DIV CLASS="test">Test</DIV>' );
1738-
* $p->next_tag( array() ) === true;
1741+
* $p->next_tag() === true;
17391742
* $p->get_tag() === 'DIV';
17401743
*
1741-
* $p->next_tag( array() ) === false;
1744+
* $p->next_tag() === false;
17421745
* $p->get_tag() === null;
17431746
* ```
17441747
*

0 commit comments

Comments
 (0)