Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
// FQN. This may be produced by Terraform 0.13.
const LegacyProviderNamespace = "-"

var allowedPattern = regexp.MustCompile("^[0-9A-Za-z](?:[0-9A-Za-z-_]{0,62}[0-9A-Za-z])?$")

Check failure on line 54 in provider.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 1.23)

undefined: regexp

Check failure on line 54 in provider.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 1.24)

undefined: regexp

Check failure on line 54 in provider.go

View workflow job for this annotation

GitHub Actions / test (macos-latest, 1.23)

undefined: regexp

Check failure on line 54 in provider.go

View workflow job for this annotation

GitHub Actions / test (macos-latest, 1.24)

undefined: regexp
// String returns an FQN string, indended for use in machine-readable output.
func (pt Provider) String() string {
if pt.IsZero() {
Expand Down Expand Up @@ -423,13 +424,24 @@
// This also, as a side-effect, prevents the use of the "punycode"
// indicator prefix "xn--" that would cause the IDNA library to interpret
// the given name as punycode, because that would be weird and unexpected.
if strings.Contains(given, "--") {
return "", fmt.Errorf("cannot use multiple consecutive dashes")

// if strings.Contains(given, "--") {
// return "", fmt.Errorf("cannot use multiple consecutive dashes")
// } //we could remove this check because ValidateLabels(true) will not allow double dashes

// Custom validation for allowed characters
if !allowedPattern.MatchString(given) {
return "", fmt.Errorf("must contain only letters, digits, dashes, and underscores, and may not use leading or trailing dashes or underscores")
}

result, err := idna.Lookup.ToUnicode(given)
opts := idna.New(idna.MapForLookup(),
idna.StrictDomainName(false),
idna.ValidateLabels(true),
idna.Transitional(false))

result, err := opts.ToUnicode(given)
if err != nil {
return "", fmt.Errorf("must contain only letters, digits, and dashes, and may not use leading or trailing dashes")
return result, fmt.Errorf("must contain only letters, digits, dashes, and underscores, and may not use leading or trailing dashes or underscores") // even when the conversion fails, it result will return the original string
}

return result, nil
Expand Down
Loading