Skip to content

Commit 0fa3cf2

Browse files
author
noah
committed
Fix the bug of asterisk
1 parent 50b62e4 commit 0fa3cf2

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

parser.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,10 @@ func parseField(field string, b bound, t translater) (bitset, error) {
127127
// parseFieldExpr returns the bits indicated by the given expression:
128128
// number | number "-" number [ "/" number ]
129129
func parseFieldExpr(fieldexpr string, b bound, t translater) (bitset, error) {
130-
if fieldexpr == "*" {
131-
return bitsetStar, nil
132-
}
130+
// Replace "*" into "min-max".
131+
newexpr := strings.Replace(fieldexpr, "*", fmt.Sprintf("%d-%d", b.min, b.max), 1)
133132

134-
rangeAndStep := strings.Split(fieldexpr, "/")
133+
rangeAndStep := strings.Split(newexpr, "/")
135134
if !(len(rangeAndStep) == 1 || len(rangeAndStep) == 2) {
136135
return 0, fmt.Errorf("Failed to parse the expr '%s', too many '/'", fieldexpr)
137136
}
@@ -172,7 +171,7 @@ func parseFieldExpr(fieldexpr string, b bound, t translater) (bitset, error) {
172171

173172
// Parse the step, second.
174173
step := 1
175-
if len(rangeAndStep) == 2 {
174+
if hasStep {
176175
var err error
177176
if step, err = strconv.Atoi(rangeAndStep[1]); err != nil {
178177
return 0, fmt.Errorf("Failed to parse the expr '%s': %w", fieldexpr, err)

parser_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func Test_parseField(t *testing.T) {
2323
{
2424
value: "*",
2525
b: boundMinute,
26-
want: bitsetStar,
26+
want: buildBitset(0, 59, 1),
2727
},
2828
{
2929
value: "5",
@@ -51,6 +51,11 @@ func Test_parseField(t *testing.T) {
5151
b: boundMinute,
5252
want: (1 << 5) | (1 << 10) | (1 << 15) | (1 << 20),
5353
},
54+
{
55+
value: "*/20",
56+
b: boundMinute,
57+
want: (1 << 0) | (1 << 20) | (1 << 40),
58+
},
5459
}
5560

5661
for _, c := range cases {

0 commit comments

Comments
 (0)