Skip to content

Commit abc8f4c

Browse files
author
alpipego
committed
validate and assign regex_limit
1 parent cb0cbf3 commit abc8f4c

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/Search_Replace_Command.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,6 @@ public function __invoke( $args, $assoc_args ) {
172172
$this->recurse_objects = \WP_CLI\Utils\get_flag_value( $assoc_args, 'recurse-objects', true );
173173
$this->verbose = \WP_CLI\Utils\get_flag_value( $assoc_args, 'verbose' );
174174
$this->format = \WP_CLI\Utils\get_flag_value( $assoc_args, 'format' );
175-
$this->regex_limit = \WP_CLI\Utils\get_flag_value( $assoc_args, 'regex-limit', -1 );
176-
if ( 0 === intval( $this->regex_limit ) ) {
177-
WP_CLI::error( '`--regex-limit` expects integer.' );
178-
}
179175

180176
if ( ( $this->regex = \WP_CLI\Utils\get_flag_value( $assoc_args, 'regex', false ) ) ) {
181177
$this->regex_flags = \WP_CLI\Utils\get_flag_value( $assoc_args, 'regex-flags', false );
@@ -204,6 +200,12 @@ public function __invoke( $args, $assoc_args ) {
204200
}
205201
WP_CLI::error( $msg );
206202
}
203+
if ( ( $regex_limit = (int) \WP_CLI\Utils\get_flag_value( $assoc_args, 'regex-limit', - 1 ) ) > - 1 ) {
204+
if ( ! preg_match( '/^[0-9]+$/', $regex_limit ) ) {
205+
WP_CLI::error( '`--regex-limit` expects a positive integer.' );
206+
}
207+
$this->regex_limit = $regex_limit;
208+
}
207209
}
208210

209211
$this->skip_columns = explode( ',', \WP_CLI\Utils\get_flag_value( $assoc_args, 'skip-columns' ) );

0 commit comments

Comments
 (0)