Skip to content

Commit

Permalink
imp - Restored integer checking
Browse files Browse the repository at this point in the history
---

We've restored checking for integers.

---

Type: imp
Breaking: False
Doc Required: False
Backport Required: False
Part: 1/1
  • Loading branch information
AptiviCEO committed Oct 2, 2024
1 parent 9af466c commit fa551a3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
24 changes: 24 additions & 0 deletions VisualCard.Calendar/Parsers/VCalendarParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,13 +287,37 @@ internal void ValidateCalendar(Parts.Calendar calendar)
throw new InvalidDataException($"The following keys [{string.Join(", ", expectedEventFields)}] are required in the event representation. Got [{string.Join(", ", actualEventFields)}].");
foreach (var alarmInfo in eventInfo.Alarms)
ValidateAlarm(alarmInfo);

// Check the priority
var priorities = eventInfo.GetInteger(CalendarIntegersEnum.PercentComplete);
foreach (var priority in priorities)
{
if (priority.Value < 0 || priority.Value > 9)
throw new ArgumentOutOfRangeException(nameof(CalendarIntegersEnum.PercentComplete), priority.Value, "Percent completion may not be less than zero or greater than 100");
}
}
foreach (var todoInfo in calendar.Todos)
{
if (!ValidateComponent(ref expectedTodoFields, out string[] actualTodoFields, todoInfo))
throw new InvalidDataException($"The following keys [{string.Join(", ", expectedTodoFields)}] are required in the todo representation. Got [{string.Join(", ", actualTodoFields)}].");
foreach (var alarmInfo in todoInfo.Alarms)
ValidateAlarm(alarmInfo);

// Check the percentage
var percentages = todoInfo.GetInteger(CalendarIntegersEnum.PercentComplete);
foreach (var percentage in percentages)
{
if (percentage.Value < 0 || percentage.Value > 100)
throw new ArgumentOutOfRangeException(nameof(CalendarIntegersEnum.PercentComplete), percentage.Value, "Percent completion may not be less than zero or greater than 100");
}

// Check the priority
var priorities = todoInfo.GetInteger(CalendarIntegersEnum.PercentComplete);
foreach (var priority in priorities)
{
if (priority.Value < 0 || priority.Value > 9)
throw new ArgumentOutOfRangeException(nameof(CalendarIntegersEnum.PercentComplete), priority.Value, "Percent completion may not be less than zero or greater than 100");
}
}

// Continue if we have a calendar with version 2.0
Expand Down
2 changes: 1 addition & 1 deletion VisualCard.Calendar/Parts/Calendar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ internal virtual void AddInteger(CalendarIntegersEnum key, CalendarValueInfo<dou

internal virtual void AddInteger(CalendarIntegersEnum key, CalendarValueInfo<double> value, Dictionary<CalendarIntegersEnum, List<CalendarValueInfo<double>>> integers)
{
if (value is null || value.Value == -1)
if (value is null || value.Value < 0)
return;

// If we don't have this key yet, add it.
Expand Down

0 comments on commit fa551a3

Please sign in to comment.