Skip to content

JsonManipulator::removeSubNode() does not remove keys that have an escaped slash #268

Backlog

Description

@manishsongirkar

Description

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 = new WP_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

  1. added
    command:package-uninstall
    on Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcommand:package-uninstall

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions