Skip to content

Commit

Permalink
Merge pull request #15502 from jasonmalinowski/do-not-crash-with-bad-…
Browse files Browse the repository at this point in the history
…serialized-data

Correctly deal with bad upstream data being fetched from the settings store
  • Loading branch information
jasonmalinowski authored Dec 5, 2016
2 parents fd9ab17 + c244596 commit 743ce3b
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 743ce3b

Please sign in to comment.