Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7f70c31

Browse files
committed
fix commented issue
1 parent 6d0d8a6 commit 7f70c31

File tree

5 files changed

+27
-14
lines changed

5 files changed

+27
-14
lines changed

‎internal/controller/nginx/config/servers.go‎

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -997,23 +997,15 @@ func exactPath(path string) string {
997997
return fmt.Sprintf("= %s", path)
998998
}
999999

1000-
func prefixPath(path string) string {
1001-
return fmt.Sprintf("^~ %s", path)
1002-
}
1003-
1004-
func regularExpressionPath(path string) string {
1005-
return fmt.Sprintf("~ %s", path)
1006-
}
1007-
10081000
// createPath builds the location path depending on the path type.
10091001
func createPath(rule dataplane.PathRule) string {
10101002
switch rule.PathType {
10111003
case dataplane.PathTypeExact:
10121004
return exactPath(rule.Path)
10131005
case dataplane.PathTypePrefix:
1014-
return prefixPath(rule.Path)
1006+
return fmt.Sprintf("^~ %s", rule.Path)
10151007
case dataplane.PathTypeRegularExpression:
1016-
return regularExpressionPath(rule.Path)
1008+
return fmt.Sprintf("~ %s", rule.Path)
10171009
default:
10181010
return "" // should never happen because path type is validated earlier
10191011
}

‎internal/controller/nginx/config/servers_test.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2682,7 +2682,7 @@ func TestCreateLocationsPath(t *testing.T) {
26822682
},
26832683
},
26842684
{
2685-
Path: "^/path/(.*)$",
2685+
Path: "^/regular-expression-path/(.*)$",
26862686
PathType: dataplane.PathTypeRegularExpression,
26872687
MatchRules: []dataplane.MatchRule{
26882688
{
@@ -2728,7 +2728,7 @@ func TestCreateLocationsPath(t *testing.T) {
27282728
Type: http.ExternalLocationType,
27292729
},
27302730
{
2731-
Path: "~ ^/path/(.*)$",
2731+
Path: "~ ^/regular-expression-path/(.*)$",
27322732
ProxyPass: "http://test_foo_80$request_uri",
27332733
ProxySetHeaders: httpBaseHeaders,
27342734
Type: http.ExternalLocationType,

‎internal/controller/nginx/config/validation/common_test.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,5 +149,7 @@ func TestValidatePathInRegexMatch(t *testing.T) {
149149
`/foo(?<!bar)`,
150150
`(\w+)1円$`,
151151
`(\w+)2円$`,
152+
`/foo/(?P<bad-name>[0-9]+)`,
153+
`/foo/(?P<bad name>[0-9]+)`,
152154
)
153155
}

‎internal/controller/state/dataplane/convert_test.go‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,10 @@ func TestConvertPathType(t *testing.T) {
551551
expected: PathTypeRegularExpression,
552552
pathType: v1.PathMatchRegularExpression,
553553
},
554+
{
555+
pathType: v1.PathMatchType("InvalidType"),
556+
panic: true,
557+
},
554558
}
555559

556560
for _, tc := range tests {

‎internal/controller/state/graph/httproute_test.go‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,12 +1161,27 @@ func TestValidateMatch(t *testing.T) {
11611161
match: gatewayv1.HTTPRouteMatch{
11621162
Path: &gatewayv1.HTTPPathMatch{
11631163
Type: helpers.GetPointer(gatewayv1.PathMatchRegularExpression),
1164-
Value: helpers.GetPointer("/"),
1164+
Value: helpers.GetPointer("/foo/(.*)$"),
11651165
},
11661166
},
11671167
expectErrCount: 0,
11681168
name: "valid regex match",
11691169
},
1170+
{
1171+
validator: func() *validationfakes.FakeHTTPFieldsValidator {
1172+
validator := createAllValidValidator()
1173+
validator.ValidatePathInRegexMatchReturns(errors.New("invalid path value"))
1174+
return validator
1175+
}(),
1176+
match: gatewayv1.HTTPRouteMatch{
1177+
Path: &gatewayv1.HTTPPathMatch{
1178+
Type: helpers.GetPointer(gatewayv1.PathMatchRegularExpression),
1179+
Value: helpers.GetPointer("(foo"),
1180+
},
1181+
},
1182+
expectErrCount: 1,
1183+
name: "bad path regex",
1184+
},
11701185
{
11711186
validator: createAllValidValidator(),
11721187
match: gatewayv1.HTTPRouteMatch{
@@ -1338,7 +1353,7 @@ func TestValidateMatch(t *testing.T) {
13381353
match: gatewayv1.HTTPRouteMatch{
13391354
Path: &gatewayv1.HTTPPathMatch{
13401355
Type: helpers.GetPointer(gatewayv1.PathMatchRegularExpression),
1341-
Value: helpers.GetPointer("/"),
1356+
Value: helpers.GetPointer("/foo/(.*)$"),
13421357
},
13431358
Headers: []gatewayv1.HTTPHeaderMatch{
13441359
{

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /