Skip to content

Commit 9c1205d

Browse files
committed
update regex
1 parent d6330fa commit 9c1205d

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

internal/k8s/validation.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,7 @@ func validateBackend(backend *networking.IngressBackend, fieldPath *field.Path)
873873
}
874874

875875
const (
876-
pathFmt = `/[^\s;\\]*`
876+
pathFmt = `/[^\s;]*`
877877
pathErrMsg = "must start with / and must not include any whitespace character or `;`"
878878
)
879879

@@ -950,7 +950,7 @@ func ValidateEscapedString(body string, examples ...string) error {
950950
}
951951

952952
const (
953-
illegalKeywordFmt = `/etc|/root`
953+
illegalKeywordFmt = `/etc|/root|\\n|\\r`
954954
illegalKeywordErrMsg = `must not contain invalid paths`
955955
)
956956

internal/k8s/validation_test.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3343,20 +3343,20 @@ func TestValidateRegexPath(t *testing.T) {
33433343
msg string
33443344
}{
33453345
{
3346-
regexPath: "~ ^/foo.*\\.jpg",
3346+
regexPath: "/foo.*\\.jpg",
33473347
msg: "case sensitive regexp",
33483348
},
33493349
{
3350-
regexPath: "~* ^/Bar.*\\.jpg",
3350+
regexPath: "/Bar.*\\.jpg",
33513351
msg: "case insensitive regexp",
33523352
},
33533353
{
3354-
regexPath: `~ ^/f\"oo.*\\.jpg`,
3354+
regexPath: `/f\"oo.*\\.jpg`,
33553355
msg: "regexp with escaped double quotes",
33563356
},
33573357
{
3358-
regexPath: "~ [0-9a-z]{4}[0-9]+",
3359-
msg: "regexp with brackets",
3358+
regexPath: "/[0-9a-z]{4}[0-9]+",
3359+
msg: "regexp with curly braces",
33603360
},
33613361
}
33623362

@@ -3375,19 +3375,19 @@ func TestValidateRegexPathFails(t *testing.T) {
33753375
msg string
33763376
}{
33773377
{
3378-
regexPath: "~ [{",
3378+
regexPath: "[{",
33793379
msg: "invalid regexp",
33803380
},
33813381
{
3382-
regexPath: `~ /foo"`,
3382+
regexPath: `/foo"`,
33833383
msg: "unescaped double quotes",
33843384
},
33853385
{
3386-
regexPath: `~"`,
3386+
regexPath: `"`,
33873387
msg: "empty regex",
33883388
},
33893389
{
3390-
regexPath: `~ /foo\`,
3390+
regexPath: `/foo\`,
33913391
msg: "ending in backslash",
33923392
},
33933393
}
@@ -3409,6 +3409,10 @@ func TestValidatePath(t *testing.T) {
34093409
"/a-1/_A/",
34103410
"/[A-Za-z]{6}/[a-z]{1,2}",
34113411
"/[0-9a-z]{4}[0-9]",
3412+
"/foo.*\\.jpg",
3413+
"/Bar.*\\.jpg",
3414+
`/f\"oo.*\\.jpg`,
3415+
"/[0-9a-z]{4}[0-9]+",
34123416
}
34133417

34143418
for _, path := range validPaths {

0 commit comments

Comments
 (0)