diff options
author | kingces95 <kingces95@users.noreply.github.com> | 2017-07-24 16:47:11 -0400 |
---|---|---|
committer | E.Z. Hart <hartez@users.noreply.github.com> | 2017-07-24 16:47:11 -0400 |
commit | 4245019418eb61c0752ac8cf8b246995906eccef (patch) | |
tree | ee6882d30168dcea66dab65245efd2153ca8c80f /Xamarin.Forms.Core/BindingExpression.cs | |
parent | 60db754eb7171d5b691fe7ae85ef25c4dcef464f (diff) | |
download | xamarin-forms-4245019418eb61c0752ac8cf8b246995906eccef.tar.gz xamarin-forms-4245019418eb61c0752ac8cf8b246995906eccef.tar.bz2 xamarin-forms-4245019418eb61c0752ac8cf8b246995906eccef.zip |
[core] Prevent canonicalization of '*.[.]' and '-0' (#1035)
Diffstat (limited to 'Xamarin.Forms.Core/BindingExpression.cs')
-rw-r--r-- | Xamarin.Forms.Core/BindingExpression.cs | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/Xamarin.Forms.Core/BindingExpression.cs b/Xamarin.Forms.Core/BindingExpression.cs index e37370d7..326ac643 100644 --- a/Xamarin.Forms.Core/BindingExpression.cs +++ b/Xamarin.Forms.Core/BindingExpression.cs @@ -361,6 +361,7 @@ namespace Xamarin.Forms } } + static Type[] DecimalTypes = new[] { typeof(float), typeof(decimal), typeof(double) }; bool TryConvert(BindingExpressionPart part, ref object value, Type convertTo, bool toTarget) { if (value == null) @@ -371,6 +372,16 @@ namespace Xamarin.Forms object original = value; try { + var stringValue = value as string ?? string.Empty; + // see: https://bugzilla.xamarin.com/show_bug.cgi?id=32871 + // do not canonicalize "*.[.]"; "1." should not update bound BindableProperty + if (stringValue.EndsWith(".") && DecimalTypes.Contains(convertTo)) + throw new FormatException(); + + // do not canonicalize "-0"; user will likely enter a period after "-0" + if (stringValue == "-0" && DecimalTypes.Contains(convertTo)) + throw new FormatException(); + value = Convert.ChangeType(value, convertTo, CultureInfo.InvariantCulture); return true; } |