squizlabs / PHP_CodeSniffer

PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.
BSD 3-Clause "New" or "Revised" License
10.67k stars 1.48k forks source link

PHP 8.1 | Tokenizer/PHP: bug fix for overeager explicit octal notation backfill #3552

Closed jrfnl closed 2 years ago

jrfnl commented 2 years ago

Follow up on #3481. /cc @MarkBaker

Just like for all other type of integer notations, if a numeric literal separator is used, it is not allowed between the prefix and the actual number.

// This is fine.
$b = 0b1_0;
$o = 0o6_3;

// This is an invalid use of the numeric literal separator.
$b = 0b_10;
$o = 0o_63;

This PR fixes the backfill for explicit octal notation to NOT backfill these type of invalid sequences as the inconsistent tokenization across PHP versions which that causes, can create havoc in sniffs.

Includes adding additional unit tests.

@gsherwood Greg - can this PR please be earmarked for PHPCS 3.7.0 to prevent the incorrect tokenization getting into a released version ?

gsherwood commented 2 years ago

Thanks a lot for finding and fixing this before release.

jrfnl commented 2 years ago

Thanks for merging this!