Skip to content

Commit 69b4d3d

Browse files
authored
Replace regex match with rune comparison (#21883)
1 parent 1922a11 commit 69b4d3d

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

Diff for: sdk/azidentity/azidentity.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"net/http"
1616
"net/url"
1717
"os"
18-
"regexp"
1918

2019
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
2120
"github.com/Azure/azure-sdk-for-go/sdk/azcore/cloud"
@@ -113,13 +112,13 @@ func resolveTenant(defaultTenant, specified, credName string, additionalTenants
113112
return "", fmt.Errorf(`%s isn't configured to acquire tokens for tenant %q. To enable acquiring tokens for this tenant add it to the AdditionallyAllowedTenants on the credential options, or add "*" to allow acquiring tokens for any tenant`, credName, specified)
114113
}
115114

116-
// validTenantID return true is it receives a valid tenantID, returns false otherwise
117115
func validTenantID(tenantID string) bool {
118-
match, err := regexp.MatchString("^[0-9a-zA-Z-.]+$", tenantID)
119-
if err != nil {
120-
return false
116+
for _, r := range tenantID {
117+
if !(('0' <= r && r <= '9') || ('a' <= r && r <= 'z') || ('A' <= r && r <= 'Z') || r == '.' || r == '-') {
118+
return false
119+
}
121120
}
122-
return match
121+
return true
123122
}
124123

125124
func newPipelineAdapter(opts *azcore.ClientOptions) pipelineAdapter {

0 commit comments

Comments
 (0)