WP_HTML_Tag_Processor::skip_rcdata( string $tag_name ): bool

This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness. Use https://html.spec.whatwg.org/multipage/parsing.html#rcdata-state instead.

Skips contents of RCDATA elements, namely title and textarea tags.

Description

See also

Parameters

$tag_namestringrequired
The uppercase tag name which will close the RCDATA region.

Return

bool Whether an end to the RCDATA region was found before the end of the document.

Source

private function skip_rcdata( $tag_name ) {
	$html       = $this->html;
	$doc_length = strlen( $html );
	$tag_length = strlen( $tag_name );

	$at = $this->bytes_already_parsed;

	while ( false !== $at && $at < $doc_length ) {
		$at = strpos( $this->html, '</', $at );

		// If there is no possible tag closer then fail.
		if ( false === $at || ( $at + $tag_length ) >= $doc_length ) {
			$this->bytes_already_parsed = $doc_length;
			return false;
		}

		$closer_potentially_starts_at = $at;
		$at                          += 2;

		/*
		 * Find a case-insensitive match to the tag name.
		 *
		 * Because tag names are limited to US-ASCII there is no
		 * need to perform any kind of Unicode normalization when
		 * comparing; any character which could be impacted by such
		 * normalization could not be part of a tag name.
		 */
		for ( $i = 0; $i < $tag_length; $i++ ) {
			$tag_char  = $tag_name[ $i ];
			$html_char = $html[ $at + $i ];

			if ( $html_char !== $tag_char && strtoupper( $html_char ) !== $tag_char ) {
				$at += $i;
				continue 2;
			}
		}

		$at                        += $tag_length;
		$this->bytes_already_parsed = $at;

		/*
		 * Ensure that the tag name terminates to avoid matching on
		 * substrings of a longer tag name. For example, the sequence
		 * "</textarearug" should not match for "</textarea" even
		 * though "textarea" is found within the text.
		 */
		$c = $html[ $at ];
		if ( ' ' !== $c && "\t" !== $c && "\r" !== $c && "\n" !== $c && '/' !== $c && '>' !== $c ) {
			continue;
		}

		while ( $this->parse_next_attribute() ) {
			continue;
		}
		$at = $this->bytes_already_parsed;
		if ( $at >= strlen( $this->html ) ) {
			return false;
		}

		if ( '>' === $html[ $at ] || '/' === $html[ $at ] ) {
			$this->bytes_already_parsed = $closer_potentially_starts_at;
			return true;
		}
	}

	return false;
}

Changelog

VersionDescription
6.2.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.