-
Notifications
You must be signed in to change notification settings - Fork 25
Deletion of constants deletes more lines than expected #53
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
Deletion of constants deletes more lines than expected #53
Conversation
|
@shreya0204 Thanks for the PR. Could you please add some tests also? |
Can you guide me on how to add for this particular fix? |
Tests regarding add/remove config is in this file - https://github.com/wp-cli/wp-config-transformer/blob/main/tests/AddRemoveTest.php This could provide idea for the test implementation. Here are the steps to run test https://github.com/wp-cli/wp-config-transformer?tab=readme-ov-file#testing |
|
@ernilambar I've implemented a new test to ensure the safe removal of constants that have concatenated strings as their values. This test specifically checks that only the targeted constant is removed, and that no additional lines or constants are inadvertently affected during the process. |
Codecov ReportAll modified and coverable lines are covered by tests ✅ 📢 Thoughts on this report? Let us know! |
Fixes #50
Fixes wp-cli/config-command#101
This pull request addresses the bug where using
wp config deleteto remove a constant fromwp-config.phpthat includes concatenated functions or complex strings results in the incorrect deletion of more than just the targeted constant.Current Behavior
Currently, when deleting a constant that includes concatenated functions or special characters, the regex used in the deletion function does not properly isolate the constant. This results in deleting additional lines or even other constants. For example:
Running
wp config delete USER_PATHwould improperly affect adjacent lines.Steps to Replicate
wp-config.phpfile with a constant definition concatenating a function.wp config delete USER_PATH.Expected Outcome
Only the line defining
USER_PATHshould be removed, leaving all other settings and definitions intact.Issue Details
The issue stemmed from the regex pattern used in the removal function, which failed to correctly identify the boundaries of the constant definition when it involved concatenated functions or complex string values.
Proposed Solution
This PR introduces a revised regex pattern that more accurately matches and isolates
definestatements, even when they contain complex string values or are among multiple statements on a single line. The new regex handles variations in whitespace and formatting, ensuring that only the specific constant is removed.