Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fixed step value validation
  • Loading branch information
jamescrosswell committed Jun 30, 2025
commit 825dd0b5fd93d881e03274eaa47b4ff956942dfb
9 changes: 2 additions & 7 deletions src/Sentry/SentryMonitorOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,7 @@ public partial class SentryMonitorOptions : ISentryJsonSerializable
// Breakdown of the validation regex pattern:
// For each time field (minute, hour, day, month, weekday):
// - Allows * for "any value"
// - Allows */n for step values where n must be:
// - Minutes: 1-59
// - Hours: 1-23
// - Days: 1-31
// - Months: 1-12
// - Weekdays: 1-7
// - Allows */n for step values where n must be any positive integer (except zero)
// - Allows single values within their valid ranges
// - Allows ranges (e.g., 8-10)
// - Allows lists of values and ranges (e.g., 6,8,9 or 8-10,12-14)
Expand All @@ -70,7 +65,7 @@ public partial class SentryMonitorOptions : ISentryJsonSerializable
// - Days: 1-31
// - Months: 1-12
// - Weekdays: 0-7 (0 and 7 both represent Sunday)
private const string ValidCrontabPattern = @"^(\*|(\*\/([1-9]|[1-5][0-9]))|([0-5]?\d)(-[0-5]?\d)?)(,([0-5]?\d)(-[0-5]?\d)?)*(\s+)(\*|(\*\/([1-9]|1[0-9]|2[0-3]))|([01]?\d|2[0-3])(-([01]?\d|2[0-3]))?)((,([01]?\d|2[0-3])(-([01]?\d|2[0-3]))?)*)?(\s+)(\*|(\*\/([1-9]|[12][0-9]|3[01]))|([1-9]|[12]\d|3[01])(-([1-9]|[12]\d|3[01]))?)((,([1-9]|[12]\d|3[01])(-([1-9]|[12]\d|3[01]))?)*)?(\s+)(\*|(\*\/([1-9]|1[0-2]))|([1-9]|1[0-2])(-([1-9]|1[0-2]))?)((,([1-9]|1[0-2])(-([1-9]|1[0-2]))?)*)?(\s+)(\*|(\*\/[1-7])|[0-7](-[0-7])?)((,[0-7](-[0-7])?)*)?$";
private const string ValidCrontabPattern = @"^(\*|(\*\/([1-9][0-9]*))|([0-5]?\d)(-[0-5]?\d)?)(,([0-5]?\d)(-[0-5]?\d)?)*(\s+)(\*|(\*\/([1-9][0-9]*))|([01]?\d|2[0-3])(-([01]?\d|2[0-3]))?)((,([01]?\d|2[0-3])(-([01]?\d|2[0-3]))?)*)?(\s+)(\*|(\*\/([1-9][0-9]*))|([1-9]|[12]\d|3[01])(-([1-9]|[12]\d|3[01]))?)((,([1-9]|[12]\d|3[01])(-([1-9]|[12]\d|3[01]))?)*)?(\s+)(\*|(\*\/([1-9][0-9]*))|([1-9]|1[0-2])(-([1-9]|1[0-2]))?)((,([1-9]|1[0-2])(-([1-9]|1[0-2]))?)*)?(\s+)(\*|(\*\/([1-9][0-9]*))|[0-7](-[0-7])?)((,[0-7](-[0-7])?)*)?$";

private SentryMonitorScheduleType _type = SentryMonitorScheduleType.None;
private string? _crontab;
Expand Down
14 changes: 7 additions & 7 deletions test/Sentry.Tests/SentryMonitorOptionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ day of month 1-31
[InlineData("0 */6 * * *")] // Every 6 hours
[InlineData("0 0 */2 * *")] // Every 2 days
[InlineData("0 0 1 */3 *")] // Every 3 months
[InlineData("*/100 * * * *")] // Step value 100 for minutes
[InlineData("* */25 * * *")] // Step value 25 for hours
[InlineData("* * */32 * *")] // Step value 32 for days
[InlineData("* * * */13 *")] // Step value 13 for months
[InlineData("* * * * */8")] // Step value 8 for weekdays
[InlineData("*/60 * * * *")] // Step value 60 for minutes
[InlineData("* */24 * * *")] // Step value 24 for hours
// Complex ranges
[InlineData("1-15 * * * *")] // Minutes 1 through 15
[InlineData("* 9-17 * * *")] // Business hours
Expand Down Expand Up @@ -77,13 +84,6 @@ public void Interval_SetMoreThanOnce_Throws()
[InlineData("* * * * 8")]
// Invalid step values
[InlineData("*/0 * * * *")] // Step value cannot be 0
[InlineData("*/100 * * * *")] // Step value too large for minutes
[InlineData("* */25 * * *")] // Step value too large for hours
[InlineData("* * */32 * *")] // Step value too large for days
[InlineData("* * * */13 *")] // Step value too large for months
[InlineData("* * * * */8")] // Step value too large for weekdays
[InlineData("*/60 * * * *")] // Step value equals max value for minutes
[InlineData("* */24 * * *")] // Step value equals max value for hours
// Invalid ranges
[InlineData("5-60 * * * *")] // Minute range exceeds 59
[InlineData("* 5-24 * * *")] // Hour range exceeds 23
Expand Down
Loading