terraform-plugin-sdk icon indicating copy to clipboard operation
terraform-plugin-sdk copied to clipboard

helper/validation: add StringRuneCountBetween() and StringBytesBetween() instead StringLenBetween()

Open ryodocx opened this issue 3 years ago • 1 comments

Summary

  • In this PullRequest, add validator in order to count string length correctly.
  • Current, StringLenBetween() count byte length.
  • For example Japanese, 1 character mean 3 bytes in UTF-8.
    • Sometimes, improper validation implements in terraform-provider via this behavior

What's changes?

  • add StringRuneCountBetween() for validate number of characters
  • add StringBytesBetween() for validate number of bytes (it's just copy of StringLenBetween())
  • StringLenBetween() is to deprecated
  • add validation for parameters(min, max)
  • add test

Related issues

  • https://github.com/hashicorp/terraform-provider-aws/issues/19846
  • https://github.com/hashicorp/terraform-provider-aws/issues/22949

ryodocx avatar Jun 19 '22 15:06 ryodocx

@bflad Could you help this PR?

ryodocx avatar Jul 17 '22 08:07 ryodocx