Repository navigation
wp post revision diff changes % sequences in changed lines, for example %20 in URLs #672
Description
Bug Report
- Yes, I reviewed the contribution guidelines.
- Yes, more specifically, I reviewed the guidelines on how to write clear bug reports.
Describe the current, buggy behavior
wp post revision diff prints the removed and added lines through WP_CLI::colorize(), but it does not escape the content first. So a % in the post content is read as the start of a color token.
The color tokens include %0 to %9. URL-encoded text is common in post content, and it breaks: my%20file.pdf is printed as my0file.pdf, and a=1%26b=2 as a=16b=2. A changed line that ends with % is printed with a literal %n at the end (100%n), because the %%n that the command builds is read as an escaped % followed by n. With --color, that line also loses its color reset.
Lines that did not change are printed without colorize(), so they look right. This means the same text looks different depending on whether the line changed, and the diff shows content that is not in either revision.
The command is in main and in the nightly build. WP-CLI 2.12.0 does not have wp post revision yet.
Describe how other contributors can replicate this bug
- Create a post, then update it twice so there are two revisions to compare.
- Use content with
%in it, for example a URL with%20. - Run
wp post revision diff <first revision> <second revision>.
$ wp post create --post_title="Percent Test" --post_content="Start" --porcelain
4
$ wp post update 4 --post_content="Progress: 100%"
Success: Updated post 4.
$ wp post update 4 --post_content="Progress: 100% of https://example.com/my%20file.pdf"
Success: Updated post 4.
$ wp post list --post_type=revision --post_parent=4 --fields=ID,post_content --orderby=ID --order=ASC
ID post_content
5 Progress: 100%
6 Progress: 100% of https://example.com/my%20file.pdf
$ wp post revision diff 5 6
--- Percent Test (2026-10-24 02:41:13) - ID 5
+++ Percent Test (2026-10-24 02:41:14) - ID 6
- Progress: 100%n
+ Progress: 100% of https://example.com/my0file.pdf
$ wp post revision diff 5 6 --color | cat -v
^[[33m--- Percent Test (2026-10-24 02:41:13) - ID 5^[[0m
^[[33m+++ Percent Test (2026-10-24 02:41:14) - ID 6^[[0m
^[[31m- Progress: 100%n
^[[32m+ Progress: 100% of https://example.com/my^[[42m0file.pdf^[[0m
With --color, %2 also turns on a green background in the middle of the line.
Describe what you would expect as the correct outcome
The diff prints each line exactly as it is stored:
- Progress: 100%
+ Progress: 100% of https://example.com/my%20file.pdf
Let us know what environment you are running this on
OS: Linux 6.18.33.2-microsoft-standard-WSL2 #1 SMP PREEMPT_DYNAMIC Thu Jun 18 21:54:43 UTC 2026 x86_64
Shell: /bin/sh
PHP binary: /usr/local/bin/php
PHP version: 8.5.9
PHP memory limit: -1
php.ini used: /usr/local/etc/php/php-cli.ini
MySQL binary: /usr/bin/mariadb
MySQL version: mariadb from 11.8.9-MariaDB, client 15.2 for Linux (x86_64) using readline 5.1
SQL modes:
WP-CLI root dir: phar://wp-cli.phar/vendor/wp-cli/wp-cli
WP-CLI vendor dir: phar://wp-cli.phar/vendor
WP_CLI phar path: phar:///tmp/wp-cli-nightly.phar
WP-CLI packages dir:
WP-CLI cache dir: /tmp/.wp-cli/cache
WP-CLI global config:
WP-CLI project config:
WP-CLI version: 3.0.0-alpha-836ccac
WordPress 7.2-beta1-64691, MariaDB 11.8.9. The output above is from entity-command main at 2078d6a. The nightly phar gives the same result.
Provide a possible solution
Escape % as %% in the line text and in the post titles before they go into WP_CLI::colorize(). php-cli-tools prints %% as a single %, with and without colors. The color tokens that the command adds itself (%g, %r, %y, %n) stay as they are.
I have a patch with a Behat test and can open a PR.
Provide additional context/Screenshots
The command was added in #563.
Activity