Still on Drupal 7? Security support for Drupal 7 ended on 5 January 2025. Please visit our Drupal 7 End of Life resources page to review all of your options.Problem/Motivation
There are some preg_match calls that can be replaced with either str_starts_with(),str_ends_with() or similar. PHPStorm has an inspection that runs this check automatically to most cases
Steps to reproduce
Proposed resolution
Do it
Remaining tasks
TBD
User interface changes
N/A
API changes
N/A
Data model changes
N/A
Release notes snippet
N/A
Issue fork drupal-3414568
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 11.x
compare
- 3414568-replace-pregmatch-with
changes, plain diff MR !6156
Comments
Comment #3
dimitriskr commentedComment #4
dimitriskr commentedComment #5
smustgrave commentedCould you post the regex you used to find those?
Comment #6
dimitriskr commentedIt was a PHPStorm inspection that identified the changes and not manually, so I got no regex for you
Comment #7
dimitriskr commentedMaybe something like this? Only for str_ends_with() replacements
https://regex101.com/r/cd29ZX/1
Comment #8
smustgrave commentedThanks used that with also phpstorm (preg_match\('\/.*) got several 100 matches but reviewed a few dozen and didn't find any additional ones that were being suggested to replace.
Comment #9
quietone commentedI'm triaging RTBC issues. I read the IS, the comments and the MR. I didn't find any unanswered questions.
I ran the inspection in PHPStorm which reported 6 problems in 4 files. Those are fixed here. There are two more changes here, one for \Drupal\Tests\views\Functional\Plugin\PagerTest::testNoLimit and the other in \Drupal\Tests\ComposerIntegrationTest::testComposerLockHash. How were these last two discovered?
I used the grep string from #8 which reports 138 matches in core. There may be more that can be changed but that should not prevent this improvement. We can also do a 'round 2'.
Leaving at RTBC;
Comment #10
dimitriskr commentedFor ComposerIntegrationTest, I asked in Slack if the replacement was valid, got only one positive response so I committed it.
As for the PagerTest, it came from a related issue and specifically this commit which was reverted there and added here
Comment #11
alexpottCommitted and pushed 4d5abf7f08 to 11.x and cc7590905b to 10.3.x. Thanks!