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 by core. It is listed here for completeness.

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

 *
 * @param string $tag_name The uppercase tag name which will close the RAWTEXT region.
 * @return bool Whether an end to the RAWTEXT region was found before the end of the document.
 */
private function skip_rawtext( string $tag_name ): bool {
	/*
	 * These two functions distinguish themselves on whether character references are
	 * decoded, and since functionality to read the inner markup isn't supported, it's
	 * not necessary to implement these two functions separately.
	 */
	return $this->skip_rcdata( $tag_name );
}

/**
 * Skips contents of RCDATA elements, namely title and textarea tags.
 *
 * @since 6.2.0
 * @ignore
 *
 * @see https://html.spec.whatwg.org/multipage/parsing.html#rcdata-state
 *
 * @param string $tag_name 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.
 */
private function skip_rcdata( string $tag_name ): bool {
	$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 );
		$this->tag_name_starts_at = $at;

		// Fail if there is no possible tag closer.
		if ( false === $at || ( $at + 2 + $tag_length ) >= $doc_length ) {
			return false;
		}

		$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;

		if ( $at >= strlen( $html ) ) {
			return false;
		}

		/*
		 * 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 && "\f" !== $c && "\r" !== $c && "\n" !== $c && '/' !== $c && '>' !== $c ) {
			continue;
		}

		while ( $this->parse_next_attribute() ) {
			continue;

Changelog

VersionDescription
6.2.0Introduced.

User Contributed Notes

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