Skip to content

Commit

Permalink
Prevent Zero Incriminators
Browse files Browse the repository at this point in the history
  • Loading branch information
maennchen committed Dec 17, 2019
1 parent 3069b0b commit 320f35a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/crontab/cron_expression/parser.ex
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@ defmodule Crontab.CronExpression.Parser do
{_, _, {_clean_divider, remainder}} when remainder != "" ->
{:error, "Can't parse #{divider} as increment."}

# Zero increment
{_, _, {0, ""}} ->
{:error, "Can't parse #{divider} as increment."}

# Found range in <start>-<end> format
{{:ok, clean_base}, _, {clean_divider, ""}} ->
{:ok, {:/, clean_base, clean_divider}}
Expand Down
4 changes: 4 additions & 0 deletions test/crontab/cron_expression/parser_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -352,4 +352,8 @@ defmodule Crontab.CronExpression.ParserTest do
test "parse invalid list element gives error" do
assert parse("* 2,4,invalid * * *") == {:error, "Can't parse invalid as hour."}
end

test "parse zero divider gives error" do
assert parse("*/0") == {:error, "Can't parse 0 as increment."}
end
end

0 comments on commit 320f35a

Please sign in to comment.