Skip to content

Commit 006a03d

Browse files
authored
Merge pull request #308 from felixbuenemann/patch-1
fix(cmd) Fix proctype regex for setting limits
2 parents 2dddbe1 + f82cf83 commit 006a03d

4 files changed

Lines changed: 11 additions & 4 deletions

File tree

cmd/limits.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ func parseLimits(limits []string) (map[string]interface{}, error) {
145145
}
146146

147147
func parseLimit(limit string) (string, string, error) {
148-
regex := regexp.MustCompile("^([A-z]+)=(([0-9]+[bkmgBKMG]{1,2}|[0-9.]{1,5}|[0-9.]{1,5}m?)(/([0-9]+[bkmgBKMG]{1,2}|[0-9.]{1,5}|[0-9.]{1,5}m?}))?)$")
148+
regex := regexp.MustCompile("^([a-z0-9]+(?:-[a-z0-9]+)*)=(([0-9]+[bkmgBKMG]{1,2}|[0-9.]{1,5}|[0-9.]{1,5}m?)(/([0-9]+[bkmgBKMG]{1,2}|[0-9.]{1,5}|[0-9.]{1,5}m?}))?)$")
149149

150150
if !regex.MatchString(limit) {
151151
return "", "", fmt.Errorf(`%s doesn't fit format type=#unit or type=# or type=#/#

cmd/limits_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,18 @@ Examples: web=2G worker=500M db=1G/2G`
3636
{"web=200m/400m", "web", "200m/400m", false, ""},
3737
{"web=0.2/0.4", "web", "0.2/0.4", false, ""},
3838
{"web=.2/.4", "web", ".2/.4", false, ""},
39+
{"web1=2G", "web1", "2G", false, ""},
40+
{"web-server=2G", "web-server", "2G", false, ""},
41+
{"web-server1=2G", "web-server1", "2G", false, ""},
3942
{"=1", "", "", true, "=1" + errorHint},
4043
{"web=", "", "", true, "web=" + errorHint},
4144
{"1=", "", "", true, "1=" + errorHint},
4245
{"web=G", "", "", true, "web=G" + errorHint},
4346
{"web=/", "", "", true, "web=/" + errorHint},
4447
{"web=/1", "", "", true, "web=/1" + errorHint},
48+
{"web-=2G", "", "", true, "web-=2G" + errorHint},
49+
{"-web=2G", "", "", true, "-web=2G" + errorHint},
50+
{"Web=2G", "", "", true, "Web=2G" + errorHint},
4551
}
4652

4753
for _, check := range cases {

cmd/ps.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,13 @@ func parseType(target string, appID string) (string, string) {
142142

143143
func parsePsTargets(targets []string) (map[string]int, error) {
144144
targetMap := make(map[string]int)
145-
regex := regexp.MustCompile(`^([a-zA-Z0-9]+(\-[a-zA-Z0-9]+)*)=([0-9]+)$`)
145+
regex := regexp.MustCompile(`^([a-z0-9]+(?:-[a-z0-9]+)*)=([0-9]+)$`)
146146
var err error
147147

148148
for _, target := range targets {
149149
if regex.MatchString(target) {
150150
captures := regex.FindStringSubmatch(target)
151-
targetMap[captures[1]], err = strconv.Atoi(captures[3])
151+
targetMap[captures[1]], err = strconv.Atoi(captures[2])
152152

153153
if err != nil {
154154
return nil, err

cmd/ps_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,10 @@ func TestParsePsTargets(t *testing.T) {
119119
{[]string{"test"}, true, nil, "'test' does not match the pattern 'type=num', ex: web=2\n"},
120120
{[]string{"test=a"}, true, nil, "'test=a' does not match the pattern 'type=num', ex: web=2\n"},
121121
{[]string{"test="}, true, nil, "'test=' does not match the pattern 'type=num', ex: web=2\n"},
122+
{[]string{"Test=2"}, true, nil, "'Test=2' does not match the pattern 'type=num', ex: web=2\n"},
122123
{[]string{"test=2"}, false, map[string]int{"test": 2}, ""},
123124
{[]string{"test-proc=2"}, false, map[string]int{"test-proc": 2}, ""},
124-
{[]string{"Test1=2"}, false, map[string]int{"Test1": 2}, ""},
125+
{[]string{"test1=2"}, false, map[string]int{"test1": 2}, ""},
125126
}
126127

127128
for _, check := range cases {

0 commit comments

Comments
 (0)