From 02eceb7049886aed5afe1e8611dca2e209b7e74c Mon Sep 17 00:00:00 2001 From: Daniel Chalmers Date: Mon, 9 Nov 2026 17:40:57 -0600 Subject: [PATCH] Fix crash when typing sc# in color box --- DesktopClock.Tests/ColorTextConverterTests.cs | 3 +++ DesktopClock/Utilities/ColorTextConverter.cs | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/DesktopClock.Tests/ColorTextConverterTests.cs b/DesktopClock.Tests/ColorTextConverterTests.cs index 49aef65..dbfbb38 100644 --- a/DesktopClock.Tests/ColorTextConverterTests.cs +++ b/DesktopClock.Tests/ColorTextConverterTests.cs @@ -48,6 +48,9 @@ public void Convert_ShowsAColorPickedElsewhereInFull() [InlineData("#FF000")] [InlineData("#GG0000")] [InlineData("Reddish")] + [InlineData("sc#")] + [InlineData("sc#1e999,0,0")] + [InlineData("ContextColor foo 1,2,3")] public void ConvertBack_RejectsUnreadableText(string text) { Assert.Equal(DependencyProperty.UnsetValue, new ColorTextConverter().ConvertBack(text, typeof(Color), null, Culture)); diff --git a/DesktopClock/Utilities/ColorTextConverter.cs b/DesktopClock/Utilities/ColorTextConverter.cs index c03d136..e69dadc 100644 --- a/DesktopClock/Utilities/ColorTextConverter.cs +++ b/DesktopClock/Utilities/ColorTextConverter.cs @@ -35,9 +35,9 @@ public object ConvertBack(object value, Type targetType, object parameter, Cultu _typedText = text; return _typedColor; } - catch (FormatException) + catch (Exception) { - // Unreadable text, like a half-typed color, leaves the color as it was and marks the box invalid. + // Unreadable text, like a half-typed color, leaves the color as it was and marks the box invalid. The error isn't always a FormatException: "sc#" gives an InvalidOperationException, and WPF doesn't catch what a converter throws. return DependencyProperty.UnsetValue; } }