Skip to content

Commit

Permalink
Deal with booleans that had been converted to integers in the cloud
Browse files Browse the repository at this point in the history
Previously, we would return the incorrectly typed data and then we'd
crash downstream of that. Now we'll be more robust, dealing with this
legacy data. Other type mismatches will also be thrown out now.

Fixes #15214.
  • Loading branch information
jasonmalinowski committed Dec 5, 2016
1 parent 121f750 commit c244596
Showing 1 changed file with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,28 @@ public bool TryFetch(OptionKey optionKey, out object value)
}
else
{
value = optionKey.Option.DefaultValue;
value = null;
return false;
}
}
else if (optionKey.Option.Type == typeof(bool) && value is int intValue)
{
// TypeScript used to store some booleans as integers. We now handle them properly for legacy sync scenarios.
value = intValue != 0;
return true;
}
else if (optionKey.Option.Type == typeof(bool) && value is long longValue)
{
// TypeScript used to store some booleans as integers. We now handle them properly for legacy sync scenarios.
value = longValue != 0;
return true;
}
else if (value != null && optionKey.Option.Type != value.GetType())
{
// We got something back different than we expected, so fail to deserialize
value = null;
return false;
}

return true;
}
Expand Down Expand Up @@ -189,4 +208,4 @@ public bool TryPersist(OptionKey optionKey, object value)
return true;
}
}
}
}

0 comments on commit c244596

Please sign in to comment.