Skip to content

Commit c567a3f

Browse files
committed
Inline is-digit and is-whitespace logic
1 parent 5942fd6 commit c567a3f

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

wp-includes/mysql/class-wp-mysql-lexer.php

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2286,10 +2286,10 @@ private function read_next_token(): int {
22862286

22872287
if ( "'" === $byte || '"' === $byte || '`' === $byte ) {
22882288
$type = $this->read_quoted_text();
2289-
} elseif ( $this->is_digit( $byte ) ) {
2289+
} elseif ( null !== $byte && strspn( $byte, self::DIGIT_MASK ) > 0 ) {
22902290
$type = $this->read_number();
22912291
} elseif ( '.' === $byte ) {
2292-
if ( $this->is_digit( $next_byte ) ) {
2292+
if ( null !== $next_byte && strspn( $next_byte, self::DIGIT_MASK ) > 0 ) {
22932293
$type = $this->read_number();
22942294
} else {
22952295
$this->bytes_already_read += 1;
@@ -2348,7 +2348,11 @@ private function read_next_token(): int {
23482348
$this->bytes_already_read += 1;
23492349
$type = self::PLUS_OPERATOR;
23502350
} elseif ( '-' === $byte ) {
2351-
if ( '-' === $next_byte && $this->is_whitespace( $this->sql[ $this->bytes_already_read + 2 ] ?? null ) ) {
2351+
if (
2352+
'-' === $next_byte
2353+
&& $this->bytes_already_read + 2 < strlen( $this->sql )
2354+
&& strspn( $this->sql[ $this->bytes_already_read + 2 ], self::WHITESPACE_MASK ) > 0
2355+
) {
23522356
$type = $this->read_line_comment();
23532357
} elseif ( '>' === $next_byte ) {
23542358
$this->bytes_already_read += 2; // Consume the '->'.
@@ -2473,7 +2477,7 @@ private function read_next_token(): int {
24732477
}
24742478
} elseif ( '#' === $byte ) {
24752479
$type = $this->read_line_comment();
2476-
} elseif ( $this->is_whitespace( $byte ) ) {
2480+
} elseif ( null !== $byte && strspn( $byte, self::WHITESPACE_MASK ) > 0 ) {
24772481
$this->bytes_already_read += strspn( $this->sql, self::WHITESPACE_MASK, $this->bytes_already_read );
24782482
$type = self::WHITESPACE;
24792483
} elseif ( '0' === $byte && ( 'x' === $next_byte || 'b' === $next_byte ) ) {
@@ -2641,11 +2645,13 @@ private function read_number(): int {
26412645
$next_byte = $this->sql[ $this->bytes_already_read + 1 ] ?? null;
26422646
$has_exponent =
26432647
( 'e' === $byte || 'E' === $byte )
2648+
&& null !== $next_byte
26442649
&& (
2645-
$this->is_digit( $next_byte )
2650+
strspn( $next_byte, self::DIGIT_MASK ) > 0
26462651
|| (
26472652
( '+' === $next_byte || '-' === $next_byte )
2648-
&& $this->is_digit( $this->sql[ $this->bytes_already_read + 2 ] ?? null )
2653+
&& $this->bytes_already_read + 2 < strlen( $this->sql )
2654+
&& strspn( $this->sql[ $this->bytes_already_read + 2 ], self::DIGIT_MASK ) > 0
26492655
)
26502656
);
26512657
if ( $has_exponent ) {
@@ -2840,14 +2846,6 @@ private function read_comment_content(): void {
28402846
}
28412847
}
28422848

2843-
private function is_whitespace( ?string $byte ): bool {
2844-
return null !== $byte && strspn( $byte, self::WHITESPACE_MASK ) > 0;
2845-
}
2846-
2847-
private function is_digit( ?string $byte ): bool {
2848-
return null !== $byte && strspn( $byte, self::DIGIT_MASK ) > 0;
2849-
}
2850-
28512849
private function determine_identifier_or_keyword_type( string $value ): int {
28522850
$value = strtoupper( $value );
28532851

0 commit comments

Comments
 (0)