feat: add validation function for string length in bytes with min and max constraints #1350
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Adds a new validation function for validating string lengths in bytes with specified minimum and maximum constraints. The new function,
StringLenBytesBetween
, ensures that the length of a given string falls within the specified byte range.Background
In many cases, especially when dealing with APIs or data storage, it is crucial to validate that string inputs meet specific length requirements to prevent errors and ensure data integrity. The existing validation functions did not provide a way to validate string lengths based on byte count, which is important for handling multi-byte characters correctly.
Related Issue
This issue has been raised in the context of ALB listener rules in Terraform AWS provider, as outlined in hashicorp/terraform-provider-aws#37802. The problem manifests when attempting to set fixed responses with multi-byte characters. For example, Japanese characters, which are typically 2-3 bytes each, quickly exceed the byte limits imposed by ALB, leading to validation errors even though the number of characters might be within acceptable limits.