Skip to content

Commit

Permalink
Adding StringComparison.InvariantCulture to IndexOf
Browse files Browse the repository at this point in the history
  • Loading branch information
Vojtěch Štorek committed Dec 12, 2024
1 parent a2e5e5e commit 17e9a35
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Src/Coravel/Scheduling/Schedule/Cron/CronExpressionPart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private bool CronExpressionPartIsDue(int time, string expression, int replaceZer
return true;
}

var isDivisibleUnit = expression.IndexOf("*/") > -1;
var isDivisibleUnit = expression.IndexOf("*/", StringComparison.InvariantCulture) > -1;

if (isDivisibleUnit)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.Globalization;
using System.Threading;
using System.Threading.Tasks;
using Coravel.Scheduling.Schedule;
using Coravel.Scheduling.Schedule.Mutex;
Expand All @@ -18,6 +20,7 @@ public class SchedulerHourlyTests
[InlineData(4, 21, 0, true)]
[InlineData(5, 23, 0, true)]
[InlineData(6, 1, 0, true)]
[InlineData(7, 1, 0, true, "th-TH")]
// Should not run
[InlineData(0, 0, 1, false)]
[InlineData(1, 4, 12, false)]
Expand All @@ -40,17 +43,34 @@ public class SchedulerHourlyTests
[InlineData(4, 21, 45, false)]
[InlineData(5, 23, 55, false)]
[InlineData(6, 1, 1, false)]
[InlineData(7, 1, 1, false, "th-TH")] // Try with different culture since it affects IndexOf calls

public async Task ValidHourly(int day, int hour, int minute, bool shouldRun)
public async Task ValidHourly(int day, int hour, int minute, bool shouldRun, string culture = null)
{
var scheduler = new Scheduler(new InMemoryMutex(), new ServiceScopeFactoryStub(), new DispatcherStub());
bool taskRan = false;
// Remember current culture in order to clean up
var prevCulture = Thread.CurrentThread.CurrentCulture;

scheduler.Schedule(() => taskRan = true).Hourly();
try
{
// Set culture if needed
if (culture != null)
Thread.CurrentThread.CurrentCulture = new CultureInfo(culture, false);

await RunScheduledTasksFromDayHourMinutes(scheduler, day, hour, minute);
var scheduler = new Scheduler(new InMemoryMutex(), new ServiceScopeFactoryStub(), new DispatcherStub());
bool taskRan = false;

Assert.Equal(shouldRun, taskRan);
scheduler.Schedule(() => taskRan = true).Hourly();

await RunScheduledTasksFromDayHourMinutes(scheduler, day, hour, minute);

Assert.Equal(shouldRun, taskRan);
}
finally
{
// Revert to previous culture if it has been changed
if (culture != null)
Thread.CurrentThread.CurrentCulture = prevCulture;
}
}
}
}

0 comments on commit 17e9a35

Please sign in to comment.