Skip to content

Commit 5715e17

Browse files
committed
INF & NAN encoding throws an exception [Closes #69]
1 parent 8e746ec commit 5715e17

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/Neon/Node/LiteralNode.php

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
namespace Nette\Neon\Node;
1111

12+
use Nette\Neon\Exception;
1213
use Nette\Neon\Node;
1314

1415

@@ -74,6 +75,9 @@ public function toString(): string
7475
return $this->value;
7576

7677
} elseif (is_float($this->value)) {
78+
if (!is_finite($this->value)) {
79+
throw new Exception('INF and NAN cannot be encoded to NEON');
80+
}
7781
$res = json_encode($this->value);
7882
return str_contains($res, '.') ? $res : $res . '.0';
7983

tests/Neon/Encoder.phpt

+6
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,9 @@ Assert::same(
164164
'[]',
165165
Neon::encode([], Neon::BLOCK),
166166
);
167+
168+
Assert::exception(
169+
fn() => Neon::encode(INF),
170+
Nette\Neon\Exception::class,
171+
'INF and NAN cannot be encoded to NEON',
172+
);

0 commit comments

Comments
 (0)