You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
JsonManipulator::removeSubNode() does not remove keys that have an escaped slash #268
JsonManipulator::removeSubNode() returns true but removes nothing when the key in composer.json is written with an escaped slash, for example "wp-cli\/foo". This happens with $caseInsensitive set to true and to false. addLink() already handles the escaped slash, so the two methods do not agree.
Where
src/WP_CLI/JsonManipulator.php, in removeSubNode():
Case-insensitive path: the loop passes the raw matched key (wp-cli\/foo) to the recursive removeSubNode() call. That key is not in the decoded data, so the call returns early and removes nothing.
Case-sensitive path: the key regexes use preg_quote( $name ). They do not accept \/, so the key is not found.
Steps to reproduce
$manipulator = newWP_CLI\JsonManipulator( '{ "require": { "wp-cli\/foo": "^1.0", "wp-cli/bar": "^1.0" }}' );
$manipulator->removeSubNode( 'require', 'wp-cli/foo', true ); // The same happens with false.echo$manipulator->getContents();
Expected
The wp-cli\/foo entry is removed.
Actual
The file is unchanged. The wp-cli\/foo entry is still there.
Impact
Low. Composer writes unescaped slashes by default. Only a file that another tool wrote with escaped slashes is affected. In that case wp package uninstall can leave the require or repositories entry in place.
Suggested fix
In the case-insensitive path, replace \/ with / before the recursive call.
In the case-sensitive path, build the key regex with \\?/, as the case-insensitive code already does.
I would like to work on this. Please assign it to me.
Activity