-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Full support for special characters in asterisk paths
- Loading branch information
Showing
5 changed files
with
120 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
internal/processing/processors/v2alpha1/virtualservice/regex_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package virtualservice | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
"regexp" | ||
) | ||
|
||
var _ = Describe("Envoy templates regex matching", func() { | ||
DescribeTable(`{\*} template`, | ||
func(input string, shouldMatch bool) { | ||
// when | ||
matched, err := regexp.MatchString(prepareRegexPath("/{*}"), input) | ||
|
||
// then | ||
Expect(err).To(Not(HaveOccurred())) | ||
Expect(matched).To(Equal(shouldMatch)) | ||
}, | ||
Entry("should not match empty path", "/", false), | ||
Entry("should match path with one segment", "/segment", true), | ||
Entry("should match special characters", "/segment-._~!$&'()*+,;=:@", true), | ||
Entry("should match with correct % encoding", "/segment%20", true), | ||
Entry("should not match with incorrect % encoding", "/segment%2", false), | ||
Entry("should not match path with multiple segments", "/segment1/segment2/segment3", false), | ||
) | ||
|
||
DescribeTable(`{\*\*} template`, func(input string, shouldMatch bool) { | ||
// when | ||
matched, err := regexp.MatchString(prepareRegexPath("/{**}"), input) | ||
|
||
// then | ||
Expect(err).To(Not(HaveOccurred())) | ||
Expect(matched).To(Equal(shouldMatch)) | ||
}, | ||
Entry("should match empty path", "/", true), | ||
Entry("should match path with one segment", "/segment", true), | ||
Entry("should match special characters", "/segment-._~!$&'()*+,;=:@", true), | ||
Entry("should match with correct % encoding", "/segment%20", true), | ||
Entry("should not match with incorrect % encoding", "/segment%2", false), | ||
Entry("should match path with multiple segments", "/segment1/segment2/segment3", true), | ||
) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters