Allow descriptions to contain newlines and other whitespace (#2599)
* Allow names and descriptions to contain newlines and other whitespace * separate validate name from validate description * update changelog --------- Co-authored-by: Danielle Miu <29378233+DanielleMiu@users.noreply.github.com>
This commit is contained in:
1 parent
08f391c5d6
commit
61e7ab4738
4 files changed
+30
-10
No files matched your search
@@ -4,6 +4,11 @@ Canonical reference for changes, improvements, and bugfixes for Boundary.
|
||||
|
||||
## Next
|
||||
|
||||
### New and Improved
|
||||
|
||||
* Allow descriptions to contain newlines and other whitespace
|
||||
([PR](https://github.com/hashicorp/boundary/pull/2599))
|
||||
|
||||
## 0.16.1 (2024/05/30)
|
||||
|
||||
### New and Improved
|
||||
|
||||
@@ -1006,7 +1006,7 @@ func validateUpdateRequest(req *pbs.UpdateScopeRequest) error {
|
||||
switch {
|
||||
case trimmed == "":
|
||||
badFields["name"] = "Cannot set empty string as name"
|
||||
case !handlers.ValidNameDescription(trimmed):
|
||||
case !handlers.ValidName(trimmed):
|
||||
badFields["name"] = "Name contains unprintable characters"
|
||||
default:
|
||||
item.GetName().Value = trimmed
|
||||
@@ -1017,7 +1017,7 @@ func validateUpdateRequest(req *pbs.UpdateScopeRequest) error {
|
||||
switch {
|
||||
case trimmed == "":
|
||||
badFields["description"] = "Cannot set empty string as description"
|
||||
case !handlers.ValidNameDescription(trimmed):
|
||||
case !handlers.ValidDescription(trimmed):
|
||||
badFields["description"] = "Description contains unprintable characters"
|
||||
default:
|
||||
item.GetDescription().Value = trimmed
|
||||
|
||||
@@ -41,7 +41,7 @@ func ValidateCreateRequest(i ApiResource, fn CustomValidatorFunc) error {
|
||||
switch {
|
||||
case trimmed == "":
|
||||
badFields["name"] = "Cannot set empty string as name"
|
||||
case !ValidNameDescription(trimmed):
|
||||
case !ValidName(trimmed):
|
||||
badFields["name"] = "Name contains unprintable characters"
|
||||
default:
|
||||
i.GetName().Value = trimmed
|
||||
@@ -52,7 +52,7 @@ func ValidateCreateRequest(i ApiResource, fn CustomValidatorFunc) error {
|
||||
switch {
|
||||
case trimmed == "":
|
||||
badFields["description"] = "Cannot set empty string as description"
|
||||
case !ValidNameDescription(trimmed):
|
||||
case !ValidDescription(trimmed):
|
||||
badFields["description"] = "Description contains unprintable characters"
|
||||
default:
|
||||
i.GetDescription().Value = trimmed
|
||||
@@ -100,7 +100,7 @@ func ValidateUpdateRequest(r UpdateRequest, i ApiResource, fn CustomValidatorFun
|
||||
switch {
|
||||
case trimmed == "":
|
||||
badFields["name"] = "Cannot set empty string as name"
|
||||
case !ValidNameDescription(trimmed):
|
||||
case !ValidName(trimmed):
|
||||
badFields["name"] = "Name contains unprintable characters"
|
||||
default:
|
||||
i.GetName().Value = trimmed
|
||||
@@ -111,7 +111,7 @@ func ValidateUpdateRequest(r UpdateRequest, i ApiResource, fn CustomValidatorFun
|
||||
switch {
|
||||
case trimmed == "":
|
||||
badFields["description"] = "Cannot set empty string as description"
|
||||
case !ValidNameDescription(trimmed):
|
||||
case !ValidDescription(trimmed):
|
||||
badFields["description"] = "Description contains unprintable characters"
|
||||
default:
|
||||
i.GetDescription().Value = trimmed
|
||||
@@ -193,7 +193,15 @@ func ValidId(i Id, prefixes ...string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func ValidNameDescription(in string) bool {
|
||||
func ValidDescription(in string) bool {
|
||||
idx := strings.IndexFunc(in, func(c rune) bool {
|
||||
return !(unicode.IsPrint(c) || unicode.IsSpace(c))
|
||||
})
|
||||
|
||||
return idx == -1
|
||||
}
|
||||
|
||||
func ValidName(in string) bool {
|
||||
idx := strings.IndexFunc(in, func(c rune) bool {
|
||||
return !unicode.IsPrint(c)
|
||||
})
|
||||
|
||||
@@ -44,9 +44,16 @@ func TestValidId(t *testing.T) {
|
||||
assert.False(t, ValidId(Id("prefix_short"), "short"))
|
||||
}
|
||||
|
||||
func TestValidNameDescription(t *testing.T) {
|
||||
assert.True(t, ValidNameDescription("foobar"))
|
||||
assert.False(t, ValidNameDescription("foo\u200Bbar"))
|
||||
func TestValidDescription(t *testing.T) {
|
||||
assert.True(t, ValidDescription("foobar"))
|
||||
assert.True(t, ValidDescription("this is\n a long description"))
|
||||
assert.False(t, ValidDescription("foo\u200Bbar"))
|
||||
}
|
||||
|
||||
func TestValidName(t *testing.T) {
|
||||
assert.True(t, ValidName("foobar"))
|
||||
assert.False(t, ValidName("this is\n a long description"))
|
||||
assert.False(t, ValidName("foo\u200Bbar"))
|
||||
}
|
||||
|
||||
func TestValidateGetRequest(t *testing.T) {
|
||||
|
||||
Reference in new issue
Block a user