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

CS: remove unnecessary ignore annotations [1] (Trac 59650) #5517

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Oct 17, 2023

It is perfectly possible to write a commented regex with layout for readability by using the x modifier.

As per the manual:

x (PCRE_EXTENDED)
If this modifier is set, whitespace data characters in the pattern are totally ignored except when escaped or inside a character class, and characters between an unescaped # outside a character class and the next newline character, inclusive, are also ignored. This is equivalent to Perl's /x modifier, and makes it possible to include commentary inside complicated patterns.
Note, however, that this applies only to data characters. Whitespace characters may never appear within special character sequences in a pattern, for example within the sequence (?( which introduces a conditional subpattern.

Ref: https://www.php.net/manual/en/reference.pcre.pattern.modifiers.php

This commit rewrites this one regex to use the x modifier and gets rid of the unnecessary phpcs:disable comments.

The tests in the tests/phpunit/tests/kses.php file cover this change.

Trac ticket: https://core.trac.wordpress.org/ticket/59650


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

It is perfectly possible to write a commented regex with layout for readability by using the `x` modifier.

As per the manual:
>  x (PCRE_EXTENDED)
>     If this modifier is set, whitespace data characters in the pattern are totally ignored except when escaped or inside a character class, and characters between an unescaped # outside a character class and the next newline character, inclusive, are also ignored. This is equivalent to Perl's /x modifier, and makes it possible to include commentary inside complicated patterns.
>     Note, however, that this applies only to data characters. Whitespace characters may never appear within special character sequences in a pattern, for example within the sequence (?( which introduces a conditional subpattern.

Ref: https://www.php.net/manual/en/reference.pcre.pattern.modifiers.php

This commit rewrites this one regex to use the `x` modifier and gets rid of the unnecessary `phpcs:disable` comments.

The tests in the `tests/phpunit/tests/kses.php` file cover this change.
@jrfnl jrfnl force-pushed the trac-59650/no-need-for-ignore-annotation-1 branch from ee4e590 to e05da6c Compare October 19, 2023 01:34
@SergeyBiryukov
Copy link
Member

Thanks for the PR! Merged in r57056.

@jrfnl
Copy link
Member Author

jrfnl commented Nov 3, 2023

Thanks again @SergeyBiryukov !

@jrfnl jrfnl deleted the trac-59650/no-need-for-ignore-annotation-1 branch November 3, 2023 22:52
@jrfnl
Copy link
Member Author

jrfnl commented Nov 3, 2023

@SergeyBiryukov Looks like the commit message is a bit borked - it references the changes from PR #5518, not the changes from this PR ?

@SergeyBiryukov
Copy link
Member

SergeyBiryukov commented Nov 4, 2023

Looks like the commit message is a bit borked - it references the changes from PR #5518, not the changes from this PR ?

Yeah, I mixed up the descriptions of the two PRs, sorry for that! Commit messages cannot be edited afterwards. At least the first sentence is accurate 🙂

@jrfnl
Copy link
Member Author

jrfnl commented Nov 4, 2023

Looks like the commit message is a bit borked - it references the changes from PR #5518, not the changes from this PR ?

Yeah, I mixed up the descriptions of the two PRs, sorry for that! Commit messages cannot be edited afterwards. At least the first sentence is accurate 🙂

@SergeyBiryukov It happens ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants