Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Infinity returns null when serialized

From RFC4627:

  Numeric values that cannot be represented as sequences of digits (such
  as Infinity and NaN) are not permitted.

NaN is invalid, so we already return null.
  • Loading branch information...
commit 857a1a0383f587c03b69f0f3afef169147975d84 1 parent e183803
@mhoran mhoran authored
Showing with 10 additions and 1 deletion.
  1. +5 −0 spec/driver_spec.rb
  2. +5 −1 src/JsonSerializer.cpp
View
5 spec/driver_spec.rb
@@ -408,6 +408,11 @@ def visit(url, driver=driver)
result.should == nil
end
+ it "evaluates Infinity and returns null" do
+ result = driver.evaluate_script(%<Infinity>)
+ result.should == nil
+ end
+
it "evaluates Javascript and returns an object" do
result = driver.evaluate_script(%<({ 'one' : 1 })>)
result.should == { 'one' => 1 }
View
6 src/JsonSerializer.cpp
@@ -1,4 +1,5 @@
#include "JsonSerializer.h"
+#include <cmath>
JsonSerializer::JsonSerializer(QObject *parent) : QObject(parent) {
}
@@ -24,7 +25,10 @@ void JsonSerializer::addVariant(const QVariant &object) {
}
break;
case QMetaType::Double:
- m_buffer.append(object.toString());
+ if (std::isinf(object.toDouble()))
+ m_buffer.append("null");
+ else
+ m_buffer.append(object.toString());
break;
case QMetaType::QVariantMap:
{
Please sign in to comment.
Something went wrong with that request. Please try again.