Skip to content

armgit / memos

Public Imported from GitHub
0

Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.

fix: user resource names can be uuidv4 from idp sub claim (#5856)

George Wubbded584ce85
diff --git a/internal/base/resource_name.go b/internal/base/resource_name.go
index 828bfa366..8731579fa 100644
--- a/internal/base/resource_name.go
+++ b/internal/base/resource_name.go
@@ -3,5 +3,5 @@ package base
import "regexp"
var (
- UIDMatcher = regexp.MustCompile("^[a-zA-Z0-9]([a-zA-Z0-9-]{0,30}[a-zA-Z0-9])?$")
+ UIDMatcher = regexp.MustCompile("^[a-zA-Z0-9]([a-zA-Z0-9-]{0,34}[a-zA-Z0-9])?$")
)
diff --git a/internal/base/resource_name_test.go b/internal/base/resource_name_test.go
index cef922ac0..88b39d307 100644
--- a/internal/base/resource_name_test.go
+++ b/internal/base/resource_name_test.go
@@ -22,6 +22,8 @@ func TestUIDMatcher(t *testing.T) {
{"a1234567890123456789012345678901", true},
{"abc123", true},
{"abc123-", false},
+ {"123e4567-e89b-12d3-a456-426614174000", true}, // UUID v4 from IDP
+ {"a123456789012345678901234567890123456", false}, // 37 characters (too long)
}
for _, test := range tests {
diff --git a/server/router/api/v1/resource_name.go b/server/router/api/v1/resource_name.go
index 070a8440a..b67d5e423 100644
--- a/server/router/api/v1/resource_name.go
+++ b/server/router/api/v1/resource_name.go
@@ -143,7 +143,7 @@ func ValidateAndGenerateUID(provided string) (string, error) {
return shortuuid.New(), nil
}
if !base.UIDMatcher.MatchString(uid) {
- return "", status.Errorf(codes.InvalidArgument, "invalid ID format: must be 1-32 characters, alphanumeric and hyphens only, cannot start or end with hyphen")
+ return "", status.Errorf(codes.InvalidArgument, "invalid ID format: must be 1-36 characters, alphanumeric and hyphens only, cannot start or end with hyphen")
}
return uid, nil
}