Skip to content

Commit 1a80fca

Browse files
vet: adds a check to disallow usage of regex.Compile in xDS code (grpc#9216)
Fixes : grpc#9153 This PR adds a check to disallow usage of `regex.Compile` in xDS code. Excludes the following from check : - all test files - internal/xds/matcher/string_matcher.go : because this is where `SafeRegex` function lives - unmarshal_rds.go - becuase `hashPoliciesProtoToSlice` needs to use it because it requires partial matches too , to replace the substring. RELEASE NOTES: None
1 parent 26ffdb3 commit 1a80fca

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

scripts/vet.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ git grep -e 'context.Background()' --or -e 'context.TODO()' -- "*_test.go" | gre
8383
# can't parse link local IPv6 addresses.
8484
not git grep 'net.ParseIP' -- '*.go'
8585

86+
# - Ensure that direct calls to regexp.Compile are not allowed in xDS production code.
87+
# Use CompileSafeRegex instead to ensure full-string matching.
88+
(git grep -n 'regexp.Compile(' -- '*xds*' ':(exclude)*_test.go' ':(exclude)internal/xds/matcher/string_matcher.go' ':(exclude)internal/xds/xdsclient/xdsresource/unmarshal_rds.go' || true) | fail_on_output || {
89+
echo "Error: direct calls to regexp.Compile are not allowed in xDS production code."
90+
echo "Please use CompileSafeRegex instead to ensure full-string matching."
91+
exit 1
92+
}
93+
8694
misspell -error .
8795

8896
# Get the absolute path to revive.toml relative to the script location

0 commit comments

Comments
 (0)