Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xds: Make regex matchers match on full string, not just partial match #4875

Merged
merged 3 commits into from
Oct 15, 2021

Conversation

zasweq
Copy link
Contributor

@zasweq zasweq commented Oct 14, 2021

This PR fixes issue #4852. Previously, regex matchers returned true even if the string had a portion that matched with the regex. The proto documentation mentions that the full value needs to match the regex, not just a portion, and this PR switches the matchers to implement that.

Fixes #4852.

RELEASE NOTES: None

@zasweq zasweq requested review from easwars and menghanl and removed request for easwars October 14, 2021 21:06
@zasweq zasweq added this to the 1.42 Release milestone Oct 14, 2021
@@ -91,7 +92,8 @@ func (hrm *HeaderRegexMatcher) Match(md metadata.MD) bool {
if !ok {
return false
}
return hrm.re.MatchString(v)
rem := hrm.re.FindString(v)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make a function (in grpcutil) to

  1. call longest()
  2. FindString and compare length

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't calling longest() more than once inefficient...it is cleaner though. It makes regex bool longest = true, then is a no op afterward. Added though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's cleaner to make longest() an implementation detail of the compare() function.

And did you forget to push?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it took me longer than expected ngl :P.

@menghanl menghanl assigned zasweq and unassigned menghanl Oct 14, 2021
@zasweq zasweq assigned menghanl and unassigned zasweq Oct 14, 2021
Copy link
Contributor

@menghanl menghanl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Can you also verify this fixes the failure in xds interop tests?

want: false,
},
{
name: "match because fully match",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a test case for Longest.
Use the regex from the example: https://pkg.go.dev/regexp#Regexp.Longest
Or https://play.golang.org/p/Z682jeK2IH6

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Pinged Eric about interop because of vet problem on master.

@menghanl
Copy link
Contributor

Try rebasing? The vet failure was fixed by #4877.

@dfawley dfawley changed the title xds: Made regex matchers match on full string, not just partial match xds: Make regex matchers match on full string, not just partial match Oct 15, 2021
@zasweq zasweq dismissed menghanl’s stale review October 15, 2021 20:11

Answered comments.

@zasweq zasweq merged commit 4757d02 into grpc:master Oct 15, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

xds: safe_regex_match should require matching whole string
2 participants