From f281005fb3a18253237c20bd3972af4a9648417a Mon Sep 17 00:00:00 2001 From: Will Fleming Date: Mon, 4 Jan 2016 16:12:30 -0500 Subject: [PATCH] PHP Parser: handle INF/NaN nodes I tracked this back to this constant number in a source file. It turns out the literal INF constant in a PHP source if fine: the parser represents constants directly using the identifier, so it's fine in JSON. But the constant number is larger than PHP's max number, so it basically overflows & get represented as INF after parsing. On the belief that similar code might result in a NaN constant, I'm also covering that one. This represents both values using constant strings that are unlikely to actually appear in anyone's source code. --- spec/cc/engine/analyzers/php/main_spec.rb | 25 +++++++++++++++++++ .../lib/PhpParser/Serializer/JSON.php | 6 ++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/spec/cc/engine/analyzers/php/main_spec.rb b/spec/cc/engine/analyzers/php/main_spec.rb index 9e37e1f0..b7c6c155 100644 --- a/spec/cc/engine/analyzers/php/main_spec.rb +++ b/spec/cc/engine/analyzers/php/main_spec.rb @@ -56,6 +56,31 @@ expect(result).to match "\"type\":\"issue\"" end + it "handles INF & NAN constants" do + create_source_file("foo.php", <<-EOPHP) + $subNode) { - if (is_string($subNode)) { + if (INF === $subNode) { + $doc[$name] = "_PHP:CONST:INF"; + } elseif (NaN === $subNode) { + $doc[$name] = "_PHP:CONST:NaN"; + } elseif (is_string($subNode)) { $doc[$name] = utf8_encode($subNode); } elseif (is_int($subNode)) { $doc[$name] = $subNode;