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

stringvalidator.OneOf is producing incorrectly escaped string #149

Closed
1 task done
mgwoj opened this issue Jul 21, 2023 · 1 comment · Fixed by #152
Closed
1 task done

stringvalidator.OneOf is producing incorrectly escaped string #149

mgwoj opened this issue Jul 21, 2023 · 1 comment · Fixed by #152
Assignees
Labels
bug Something isn't working

Comments

@mgwoj
Copy link

mgwoj commented Jul 21, 2023

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

  • I agree to follow this project's Code of Conduct
@github-actions
Copy link

github-actions bot commented Sep 3, 2023

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
3 participants