summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Core
diff options
context:
space:
mode:
authorkingces95 <kingces95@users.noreply.github.com>2017-07-24 20:47:11 (GMT)
committerE.Z. Hart <hartez@users.noreply.github.com>2017-07-24 20:47:11 (GMT)
commit4245019418eb61c0752ac8cf8b246995906eccef (patch)
treeee6882d30168dcea66dab65245efd2153ca8c80f /Xamarin.Forms.Core
parent60db754eb7171d5b691fe7ae85ef25c4dcef464f (diff)
downloadxamarin-forms-4245019418eb61c0752ac8cf8b246995906eccef.zip
xamarin-forms-4245019418eb61c0752ac8cf8b246995906eccef.tar.gz
xamarin-forms-4245019418eb61c0752ac8cf8b246995906eccef.tar.bz2
[core] Prevent canonicalization of '*.[.]' and '-0' (#1035)
Diffstat (limited to 'Xamarin.Forms.Core')
-rw-r--r--Xamarin.Forms.Core/BindingExpression.cs11
1 files changed, 11 insertions, 0 deletions
diff --git a/Xamarin.Forms.Core/BindingExpression.cs b/Xamarin.Forms.Core/BindingExpression.cs
index e37370d..326ac64 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;
}