From cbfbaf7412ea64fcb58b3a689d9fdb66f8e6a4a0 Mon Sep 17 00:00:00 2001 From: Brandon Payton Date: Tue, 9 May 2023 20:47:42 -0400 Subject: [PATCH 1/3] Fix regex invalid delimiter test for PHP 8.2 --- features/search-replace.feature | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/features/search-replace.feature b/features/search-replace.feature index 15977274..1b511e73 100644 --- a/features/search-replace.feature +++ b/features/search-replace.feature @@ -396,14 +396,6 @@ Feature: Do global search/replace https://example.com """ - When I try `wp search-replace 'HTTPS://EXAMPLE.COM' 'https://example.jp/' wp_options --regex --regex-flags=i --regex-delimiter='1'` - Then STDERR should be: - """ - Error: The regex '1HTTPS://EXAMPLE.COM1i' fails. - preg_match(): Delimiter must not be alphanumeric or backslash. - """ - And the return code should be 1 - When I try `wp search-replace 'regex error)' '' --regex` Then STDERR should contain: """ @@ -464,6 +456,30 @@ Feature: Do global search/replace """ And the return code should be 1 + @less-than-php-8.2 + Scenario: Search replace with an invalid regex delimiter + Given a WP install + + When I try `wp search-replace 'HTTPS://EXAMPLE.COM' 'https://example.jp/' wp_options --regex --regex-flags=i --regex-delimiter='1'` + Then STDERR should be: + """ + Error: The regex '1HTTPS://EXAMPLE.COM1i' fails. + preg_match(): Delimiter must not be alphanumeric or backslash. + """ + And the return code should be 1 + + @require-php-8.2 + Scenario: Search replace with an invalid regex delimiter + Given a WP install + + When I try `wp search-replace 'HTTPS://EXAMPLE.COM' 'https://example.jp/' wp_options --regex --regex-flags=i --regex-delimiter='1'` + Then STDERR should be: + """ + Error: The regex '1HTTPS://EXAMPLE.COM1i' fails. + preg_match(): Delimiter must not be alphanumeric, backslash, or NUL. + """ + And the return code should be 1 + Scenario: Formatting as count-only Given a WP install And I run `wp option set foo 'ALPHA.example.com'` From b1671b57f5dae672fad2efcc7a71fd67628b97dd Mon Sep 17 00:00:00 2001 From: Brandon Payton Date: Wed, 10 May 2023 10:48:51 -0400 Subject: [PATCH 2/3] Use single test that works for all tested PHP versions Co-authored-by: Alain Schlesser --- features/search-replace.feature | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/features/search-replace.feature b/features/search-replace.feature index 1b511e73..c91d1ff8 100644 --- a/features/search-replace.feature +++ b/features/search-replace.feature @@ -456,30 +456,17 @@ Feature: Do global search/replace """ And the return code should be 1 - @less-than-php-8.2 Scenario: Search replace with an invalid regex delimiter Given a WP install + # Exact preg_match() error changed with PHP 8.2+ (added NUL). When I try `wp search-replace 'HTTPS://EXAMPLE.COM' 'https://example.jp/' wp_options --regex --regex-flags=i --regex-delimiter='1'` - Then STDERR should be: - """ - Error: The regex '1HTTPS://EXAMPLE.COM1i' fails. - preg_match(): Delimiter must not be alphanumeric or backslash. - """ - And the return code should be 1 - - @require-php-8.2 - Scenario: Search replace with an invalid regex delimiter - Given a WP install - - When I try `wp search-replace 'HTTPS://EXAMPLE.COM' 'https://example.jp/' wp_options --regex --regex-flags=i --regex-delimiter='1'` - Then STDERR should be: + Then STDERR should contain: """ Error: The regex '1HTTPS://EXAMPLE.COM1i' fails. - preg_match(): Delimiter must not be alphanumeric, backslash, or NUL. + preg_match(): Delimiter must not be alphanumeric """ And the return code should be 1 - Scenario: Formatting as count-only Given a WP install And I run `wp option set foo 'ALPHA.example.com'` From 536a5277b6a2c77f8a316f561793aea3a51c1b82 Mon Sep 17 00:00:00 2001 From: Brandon Payton Date: Wed, 10 May 2023 11:09:48 -0400 Subject: [PATCH 3/3] Restore previous test position and clarify comment --- features/search-replace.feature | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/features/search-replace.feature b/features/search-replace.feature index c91d1ff8..e225b592 100644 --- a/features/search-replace.feature +++ b/features/search-replace.feature @@ -396,6 +396,19 @@ Feature: Do global search/replace https://example.com """ + # NOTE: The preg_match() error message is a substring of the actual message that matches across supported PHP versions. + # In PHP 8.2, the error message changed from + # "preg_match(): Delimiter must not be alphanumeric or backslash." + # to + # "preg_match(): Delimiter must not be alphanumeric, backslash, or NUL" + When I try `wp search-replace 'HTTPS://EXAMPLE.COM' 'https://example.jp/' wp_options --regex --regex-flags=i --regex-delimiter='1'` + Then STDERR should contain: + """ + Error: The regex '1HTTPS://EXAMPLE.COM1i' fails. + preg_match(): Delimiter must not be alphanumeric + """ + And the return code should be 1 + When I try `wp search-replace 'regex error)' '' --regex` Then STDERR should contain: """ @@ -456,17 +469,6 @@ Feature: Do global search/replace """ And the return code should be 1 - Scenario: Search replace with an invalid regex delimiter - Given a WP install - - # Exact preg_match() error changed with PHP 8.2+ (added NUL). - When I try `wp search-replace 'HTTPS://EXAMPLE.COM' 'https://example.jp/' wp_options --regex --regex-flags=i --regex-delimiter='1'` - Then STDERR should contain: - """ - Error: The regex '1HTTPS://EXAMPLE.COM1i' fails. - preg_match(): Delimiter must not be alphanumeric - """ - And the return code should be 1 Scenario: Formatting as count-only Given a WP install And I run `wp option set foo 'ALPHA.example.com'`