Skip to content

wp search-replace --dry-run --log counts the same row twice for plain and JSON-escaped URLs #255

Backlog

Description

@elphizu

Bug Report

Describe the current, buggy behavior

When post_content contains both https://old.example and its JSON-escaped form https:\/\/old.example, wp search-replace --dry-run reports one replacement. Adding --log reports two for the same row and column.

Describe how other contributors can replicate this bug

Run these commands on a fresh WordPress test site with MariaDB and the default wp_ table prefix.

wp eval '
    $url = "https://old.example";
    $escaped = substr( json_encode( $url ), 1, -1 );
    $post_id = wp_insert_post( [
        "post_title"   => "Search-replace count fixture",
        "post_status"  => "draft",
        "post_content" => wp_slash( "Plain: $url\nEscaped: $escaped" ),
    ], true );
    if ( is_wp_error( $post_id ) ) {
        WP_CLI::error( $post_id->get_error_message() );
    }
    echo "Fixture post ID: $post_id\n";
'
wp search-replace https://old.example https://new.example wp_posts \
  --include-columns=post_content --dry-run
wp search-replace https://old.example https://new.example wp_posts \
  --include-columns=post_content --dry-run --log=replace.log

Compare the reported replacement counts for wp_posts.post_content.

Command options Reported replacements
--dry-run 1
--dry-run --log=replace.log 2

Describe what you would expect as the correct outcome

Both dry runs should report one replacement. The log can still show both matches.

Let us know what environment you are running this on

Relevant lines from wp cli info:

OS: Darwin 27.2.0 (arm64)
Shell: /bin/zsh
PHP version: 8.4.28
WP-CLI version: 3.0.1
  • wp-cli/search-replace-command v3.1.0 (17063d6f)
  • WordPress 7.1.5
  • MariaDB 11.4.14

Provide a possible solution

The SQL dry-run branch adds the row counts from two log_sql_diff() calls. Count each matching row once per column across both calls. Search_Replace_Command.php

Provide additional context/Screenshots

replace.log shows the same post ID twice, once for each URL form.

Activity

  1. added
    command:search-replace
    status:unconfirmed
    on Dec 3, 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:search-replacestatus:unconfirmed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions