Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTML API: Fix CDATA section null and whitespace handling #7230

18 changes: 17 additions & 1 deletion src/wp-includes/html-api/class-wp-html-processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -4113,9 +4113,25 @@
return true;

/*
* > A comment token
* A CDATA section is effectively a text node and should have similar handling.
*/
case '#cdata-section':
/*
* NULL bytes and whitespace do not change the frameset-ok flag.
*/
$current_token = $this->bookmarks[ $this->state->current_token->bookmark_name ];
sirreal marked this conversation as resolved.
Show resolved Hide resolved
$cdata_content_start = $current_token->start + 9;
$cdata_content_length = $current_token->length - 12;
if ( $cdata_content_length !== strspn( $this->html, "\0 \t\n\f\r", $cdata_content_start, $cdata_content_length ) ) {

Check failure on line 4125 in src/wp-includes/html-api/class-wp-html-processor.php

View workflow job for this annotation

GitHub Actions / PHP coding standards / Run coding standards checks

Use Yoda Condition checks, you must.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The yoda condition PHPCS flagged here seems to be a false positive. I suspect it's confusing a string literal on the line with a literal comparison, but the string literal is not being compared. It's fine to have it on the other side…

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it doesn't define Yoda conditions the way most of us do, I think. by flipping this conditional it's happy.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect it was finding a literal in the RHS of the comparison and thinking that literal are supposed to go on the left (yoda), but it ignores the fact that the literal is in a function call. But that's just my intuition.

Switching the order is fine if it satisfies the linter 🤷

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it's the variable on the left hand side that it doesn't like, unless both are variables, in which case it's happy and doesn't care.

joda condition checks like these aren't about literals, but accidental assignment to a variable.

$this->state->frameset_ok = false;
}

$this->insert_foreign_element( $this->state->current_token, false );
return true;

/*
* > A comment token
*/
case '#comment':
case '#funky_comment':
$this->insert_foreign_element( $this->state->current_token, false );
Expand Down
Loading