Skip to content

Commit

Permalink
Fix checks
Browse files Browse the repository at this point in the history
  • Loading branch information
dmsnell committed Nov 29, 2023
1 parent 1a045da commit 356bc7c
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/wp-includes/html-api/class-wp-html-tag-processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,10 @@ public function next_tag( $query = null ) {
public function next_token() {
$was_at = $this->bytes_already_parsed;

if ( $was_at >= strlen( $this->html ) ) {
if (
self::STATE_COMPLETE === $this->continuation_state ||
$was_at >= strlen( $this->html )
) {
$this->continuation_state = self::STATE_COMPLETE;
return false;
}
Expand All @@ -637,15 +640,20 @@ public function next_token() {

// Find the next tag if it exists.
if ( false === $this->parse_next_tag() ) {
if ( $this->bytes_already_parsed > $was_at ) {
if (
$this->bytes_already_parsed <= strlen( $this->html ) &&
$this->bytes_already_parsed > $was_at
) {
$this->continuation_state = self::STATE_COMPLETE;
$this->last_token_type = self::TEXT_NODE;
$this->tag_name_starts_at = $was_at;
$this->tag_name_length = strlen( $this->html ) - $was_at;
$this->token_starts_at = $was_at;
$this->text_starts_at = $was_at;
$this->text_length = strlen( $this->html ) - $this->text_starts_at;
$this->token_length = strlen( $this->html ) - $was_at;
return true;
}

$this->continuation_state = self::STATE_INCOMPLETE;
$this->continuation_state = self::STATE_INCOMPLETE;
return false;
}

Expand All @@ -666,13 +674,12 @@ public function next_token() {

$tag_ends_at = strpos( $this->html, '>', $this->bytes_already_parsed );
if ( false === $tag_ends_at ) {
$this->continuation_state = self::STATE_INCOMPLETE;
$this->continuation_state = self::STATE_INCOMPLETE;
return false;
}

$this->tag_ends_at = $tag_ends_at;
$this->bytes_already_parsed = min( strlen( $this->html ) - 1, $tag_ends_at + 1 );
$this->last_token_type = self::ELEMENT_NODE;

/*
* For non-DATA sections which might contain text that looks like HTML tags but
Expand Down

0 comments on commit 356bc7c

Please sign in to comment.