hashicorp / terraform-plugin-framework-validators

Common Use Case Validators for terraform-plugin-framework
Mozilla Public License 2.0
25 stars 11 forks source link

stringvalidator.OneOf is producing incorrectly escaped string #149

Closed mgwoj closed 1 year ago

mgwoj commented 1 year ago

Terraform CLI and Framework Versions

Terraform v1.4.5 github.com/hashicorp/terraform-plugin-framework v1.2.0

Terraform Plugin Framework Code

func (v oneOfValidator) MarkdownDescription(_ context.Context) string {
    return fmt.Sprintf("value must be one of: %q", v.values)
}

Terraform Configuration

Validators: []validator.String{stringvalidator.OneOf("LIVE", "LIVE_VOD", "WEB_STANDARD_TLS", "WEB_ENHANCED_TLS")},

Expected Behavior

    Attribute traffic_type value must be one of: ["LIVE" "LIVE_VOD"
    "WEB_STANDARD_TLS" "WEB_ENHANCED_TLS"], got: "TEST"

Actual Behavior

    Attribute traffic_type value must be one of: ["\"LIVE\"" "\"LIVE_VOD\""
    "\"WEB_STANDARD_TLS\"" "\"WEB_ENHANCED_TLS\""], got: "TEST"

Steps to Reproduce

.

Logs

No response

Additional Information

The problem is that MarkdownDescription function for OneOf validator is using %q to escape and build string representation for the array of strings. In normal situation it would work perfectly when the values are defined as []string. However this validator is using values defined as []types.String and types.String has its own implementation of String() function which is also escaping the string value using %q. As the result there is double escaping, generating confusing \" in the output message. Please modify MarkdownDescription and implement own concatenation of string values. I guess similar issue is for other string validators.

Code of Conduct

github-actions[bot] commented 1 year ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.