Commit 5715e17 1 parent 8e746ec commit 5715e17 Copy full SHA for 5715e17
File tree 2 files changed +10
-0
lines changed
2 files changed +10
-0
lines changed Original file line number Diff line number Diff line change 9
9
10
10
namespace Nette \Neon \Node ;
11
11
12
+ use Nette \Neon \Exception ;
12
13
use Nette \Neon \Node ;
13
14
14
15
@@ -74,6 +75,9 @@ public function toString(): string
74
75
return $ this ->value ;
75
76
76
77
} elseif (is_float ($ this ->value )) {
78
+ if (!is_finite ($ this ->value )) {
79
+ throw new Exception ('INF and NAN cannot be encoded to NEON ' );
80
+ }
77
81
$ res = json_encode ($ this ->value );
78
82
return str_contains ($ res , '. ' ) ? $ res : $ res . '.0 ' ;
79
83
Original file line number Diff line number Diff line change @@ -164,3 +164,9 @@ Assert::same(
164
164
'[] ' ,
165
165
Neon::encode ([], Neon::BLOCK ),
166
166
);
167
+
168
+ Assert::exception (
169
+ fn () => Neon::encode (INF ),
170
+ Nette \Neon \Exception::class,
171
+ 'INF and NAN cannot be encoded to NEON ' ,
172
+ );
You can’t perform that action at this time.
0 commit comments