From 784d8c7bf4a906c5dfef450fde8d7fff4e1a752d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=95=E6=B5=B7=E6=B6=9B?= Date: Mon, 25 Sep 2017 12:20:14 +0800 Subject: [PATCH 1/2] fix convert int to float issue --- src/Toml.php | 2 +- travis-test/example.toml | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Toml.php b/src/Toml.php index dd91bca..6f05205 100755 --- a/src/Toml.php +++ b/src/Toml.php @@ -557,7 +557,7 @@ private static function parseValue($val) { $val = str_replace('_', '', $val); - if(is_int($val)) + if(ctype_digit($val)) { $parsedVal = (int) $val; } diff --git a/travis-test/example.toml b/travis-test/example.toml index 1ad4a4d..b5f9e75 100644 --- a/travis-test/example.toml +++ b/travis-test/example.toml @@ -249,3 +249,5 @@ color = "gray" [user.contributed.cases] slashes="SERVER\\MASTER" + +foo = [1,2,3.1] From cfb54df529742c5607907822990bd360e59c45c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=95=E6=B5=B7=E6=B6=9B?= Date: Mon, 25 Sep 2017 13:58:37 +0800 Subject: [PATCH 2/2] fix int parser for plus/minus sign --- src/Toml.php | 5 +++-- travis-test/example.toml | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Toml.php b/src/Toml.php index 6f05205..4da5b51 100755 --- a/src/Toml.php +++ b/src/Toml.php @@ -557,9 +557,10 @@ private static function parseValue($val) { $val = str_replace('_', '', $val); - if(ctype_digit($val)) + $intVal = filter_var($val, FILTER_VALIDATE_INT); + if($intVal !== false) { - $parsedVal = (int) $val; + $parsedVal = $intVal; } else { diff --git a/travis-test/example.toml b/travis-test/example.toml index b5f9e75..b3fa8a8 100644 --- a/travis-test/example.toml +++ b/travis-test/example.toml @@ -250,4 +250,4 @@ color = "gray" [user.contributed.cases] slashes="SERVER\\MASTER" -foo = [1,2,3.1] +foo = [1,2,3.1, +1, -1, -2.5]