Skip to content

Commit aab939f

Browse files
authored
Merge pull request #46 from wp-cli/change-default-delimiter
Change default regex delimiter to `chr(1)`
2 parents 1501796 + f75e8ab commit aab939f

File tree

2 files changed

+13
-17
lines changed

2 files changed

+13
-17
lines changed

features/db-search.feature

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -702,18 +702,22 @@ Feature: Search through the database
702702
Then STDOUT should be empty
703703

704704
When I try `wp db search 'unfindable' --regex --regex-flags='abcd'`
705-
Then STDERR should be:
705+
Then STDERR should contain:
706+
"""
707+
unfindable
706708
"""
707-
Error: The regex '/unfindable/abcd' fails.
709+
And STDERR should contain:
708710
"""
709-
Then the return code should be 1
711+
abcd
712+
"""
713+
And the return code should be 1
710714

711715
When I try `wp db search 'unfindable' --regex --regex-delimiter='1'`
712716
Then STDERR should be:
713717
"""
714718
Error: The regex '1unfindable1' fails.
715719
"""
716-
Then the return code should be 1
720+
And the return code should be 1
717721

718722
When I run `wp db search '[0-9é]+?https:' --regex --regex-flags=u --before_context=0 --after_context=0`
719723
Then STDOUT should contain:
@@ -804,13 +808,8 @@ Feature: Search through the database
804808
st.com
805809
"""
806810

807-
When I try `wp db search 'https://' --regex`
808-
Then STDERR should contain:
809-
"""
810-
Error: The regex '/https:///' fails.
811-
"""
812-
And STDOUT should be empty
813-
And the return code should be 1
811+
When I run `wp db search 'https://' --regex`
812+
Then the return code should be 0
814813

815814
@require-wp-4.7
816815
Scenario: Search with output options

src/DB_Command.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -721,10 +721,7 @@ public function prefix() {
721721
* : Pass PCRE modifiers to the regex search (e.g. 'i' for case-insensitivity). Note that 'u' (UTF-8 mode) will not be automatically added.
722722
*
723723
* [--regex-delimiter=<regex-delimiter>]
724-
* : The delimiter to use for the regex. It must be escaped if it appears in the search string.
725-
* ---
726-
* default: /
727-
* ---
724+
* : The delimiter to use for the regex. It must be escaped if it appears in the search string. The default value is the result of `chr(1)`.
728725
*
729726
* [--table_column_once]
730727
* : Output the 'table:column' line once before all matching row lines in the table column rather than before each matching row.
@@ -820,9 +817,9 @@ public function search( $args, $assoc_args ) {
820817

821818
if ( ( $regex = \WP_CLI\Utils\get_flag_value( $assoc_args, 'regex', false ) ) ) {
822819
$regex_flags = \WP_CLI\Utils\get_flag_value( $assoc_args, 'regex-flags', false );
823-
$regex_delimiter = \WP_CLI\Utils\get_flag_value( $assoc_args, 'regex-delimiter', '/' );
820+
$regex_delimiter = \WP_CLI\Utils\get_flag_value( $assoc_args, 'regex-delimiter', chr( 1 ) );
824821
if ( '' === $regex_delimiter ) {
825-
$regex_delimiter = '/';
822+
$regex_delimiter = chr( 1 );
826823
}
827824
}
828825

0 commit comments

Comments
 (0)