Unverified Commit 663d0b13 authored by LongCatIsLooong's avatar LongCatIsLooong Committed by GitHub

Fix double.infinity serialization (#40099)

parent 477ae6b8
...@@ -2669,7 +2669,11 @@ class DiagnosticsProperty<T> extends DiagnosticsNode { ...@@ -2669,7 +2669,11 @@ class DiagnosticsProperty<T> extends DiagnosticsNode {
json['defaultLevel'] = describeEnum(_defaultLevel); json['defaultLevel'] = describeEnum(_defaultLevel);
if (value is Diagnosticable || value is DiagnosticsNode) if (value is Diagnosticable || value is DiagnosticsNode)
json['isDiagnosticableValue'] = true; json['isDiagnosticableValue'] = true;
if (value is num || value is String || value is bool || value == null) if (v is num)
// Workaround for https://github.com/flutter/flutter/issues/39937#issuecomment-529558033.
// JSON.stringify replaces infinity and NaN with null.
json['value'] = v.isFinite ? v : v.toString();
if (value is String || value is bool || value == null)
json['value'] = value; json['value'] = value;
return json; return json;
} }
......
...@@ -1050,6 +1050,15 @@ void main() { ...@@ -1050,6 +1050,15 @@ void main() {
validateDoublePropertyJsonSerialization(doubleWithUnit); validateDoublePropertyJsonSerialization(doubleWithUnit);
}); });
test('double.infinity serialization test', () {
final DoubleProperty infProperty1 = DoubleProperty('double1', double.infinity);
validateDoublePropertyJsonSerialization(infProperty1);
expect(infProperty1.toString(), equals('double1: Infinity'));
final DoubleProperty infProperty2 = DoubleProperty('double2', double.negativeInfinity);
validateDoublePropertyJsonSerialization(infProperty2);
expect(infProperty2.toString(), equals('double2: -Infinity'));
});
test('unsafe double property test', () { test('unsafe double property test', () {
final DoubleProperty safe = DoubleProperty.lazy( final DoubleProperty safe = DoubleProperty.lazy(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment