Skip to content

Commit 38178f4

Browse files
committed
Tokenizer/PHP: bug fix for potential "Uninitialized string offset 1"
... in the backfill for the PHP 8.1 explicit octal notation. Includes unit tests.
1 parent ed8e00d commit 38178f4

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

src/Tokenizers/PHP.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,7 @@ protected function tokenize($string)
750750
&& (isset($tokens[($stackPtr + 1)]) === true
751751
&& is_array($tokens[($stackPtr + 1)]) === true
752752
&& $tokens[($stackPtr + 1)][0] === T_STRING
753+
&& isset($tokens[($stackPtr + 1)][1][0], $tokens[($stackPtr + 1)][1][1]) === true
753754
&& strtolower($tokens[($stackPtr + 1)][1][0]) === 'o'
754755
&& $tokens[($stackPtr + 1)][1][1] !== '_')
755756
&& preg_match('`^(o[0-7]+(?:_[0-7]+)?)([0-9_]*)$`i', $tokens[($stackPtr + 1)][1], $matches) === 1

tests/Core/Tokenizer/BackfillExplicitOctalNotationTest.inc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,6 @@ $foo = 0o28_2;
2626

2727
/* testInvalid6 */
2828
$foo = 0o2_82;
29+
30+
/* testInvalid7 */
31+
$foo = 0o;

tests/Core/Tokenizer/BackfillExplicitOctalNotationTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ public function dataExplicitOctalNotation()
106106
'nextToken' => T_STRING,
107107
'nextContent' => '_82',
108108
],
109+
[
110+
'marker' => '/* testInvalid7 */',
111+
'value' => '0',
112+
'nextToken' => T_STRING,
113+
'nextContent' => 'o',
114+
],
109115
];
110116

111117
}//end dataExplicitOctalNotation()

0 commit comments

Comments
 (0)