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.

feat: allow single letter user id (#3991)

Roman310f1479112a
diff --git a/internal/util/resource_name.go b/internal/util/resource_name.go
index f7a1124a9..ea40eb845 100644
--- a/internal/util/resource_name.go
+++ b/internal/util/resource_name.go
@@ -3,5 +3,5 @@ package util
import "regexp"
var (
- UIDMatcher = regexp.MustCompile("^[a-zA-Z0-9]([a-zA-Z0-9-]{1,30}[a-zA-Z0-9])$")
+ UIDMatcher = regexp.MustCompile("^[a-zA-Z0-9]([a-zA-Z0-9-]{0,30}[a-zA-Z0-9])?$")
)
diff --git a/test/util/resource_name_test.go b/test/util/resource_name_test.go
new file mode 100644
index 000000000..fecd33547
--- /dev/null
+++ b/test/util/resource_name_test.go
@@ -0,0 +1,37 @@
+package util_test
+
+import (
+ "testing"
+
+ "github.com/usememos/memos/internal/util"
+)
+
+func TestUIDMatcher(t *testing.T) {
+ tests := []struct {
+ input string
+ expected bool
+ }{
+ {"", false},
+ {"-abc123", false},
+ {"012345678901234567890123456789", true},
+ {"1abc-123", true},
+ {"A123B456C789", true},
+ {"a", true},
+ {"ab", true},
+ {"a*b&c", false},
+ {"a--b", true},
+ {"a-1b-2c", true},
+ {"a1234567890123456789012345678901", true},
+ {"abc123", true},
+ {"abc123-", false},
+ }
+
+ for _, test := range tests {
+ t.Run(test.input, func(t *testing.T) {
+ result := util.UIDMatcher.MatchString(test.input)
+ if result != test.expected {
+ t.Errorf("For input '%s', expected %v but got %v", test.input, test.expected, result)
+ }
+ })
+ }
+}