Skip to content

Commit 32877c4

Browse files
committed
Merge #286 - replace sscanf by equivalent native PHP functions because sscanf can be disabled for security reasons.
Pull-request: #286 Fixes: #270 Signed-off-by: William Desportes <[email protected]>
2 parents c690e1d + 8ea41bc commit 32877c4

File tree

3 files changed

+11
-12
lines changed

3 files changed

+11
-12
lines changed

src/Token.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -258,17 +258,16 @@ public function extract()
258258
if ($this->flags & self::FLAG_NUMBER_HEX) {
259259
if ($this->flags & self::FLAG_NUMBER_NEGATIVE) {
260260
$ret = str_replace('-', '', $this->token);
261-
sscanf($ret, '%x', $ret);
262-
$ret = -$ret;
261+
$ret = -hexdec($ret);
263262
} else {
264-
sscanf($ret, '%x', $ret);
263+
$ret = hexdec($ret);
265264
}
266265
} elseif (($this->flags & self::FLAG_NUMBER_APPROXIMATE)
267266
|| ($this->flags & self::FLAG_NUMBER_FLOAT)
268267
) {
269-
sscanf($ret, '%f', $ret);
270-
} else {
271-
sscanf($ret, '%d', $ret);
268+
$ret = (float) $ret;
269+
} elseif (! ($this->flags & self::FLAG_NUMBER_BINARY)) {
270+
$ret = (int) $ret;
272271
}
273272

274273
return $ret;

tests/data/lexer/lexNumber.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
SELECT 12, 34, 5.67, 0x89, -10, --11, +12, .15, 0xFFa, 0xfFA, 0XFfA, 1e-10, 1e10, .5e10, b'10';
1+
SELECT 12, 34, 5.67, 0x89, -10, --11, +12, .15, 0xFFa, 0xfFA, 0XFfA, -0xFFa, -0xfFA, -0XFfA, 1e-10, 1e10, .5e10, b'10';
22
-- invalid number
33
SELECT 12ex10, b'15';

0 commit comments

Comments
 (0)