mirror of
https://github.com/usememos/memos.git
synced 2025-03-28 16:40:14 +01:00
feat: allow single letter user id (#3991)
* Allow single letter user id. They do work - I use one and login using Authelia, but then I am not able to update the profile to update avatar or add comment because "Invalid username: r" errors * Add test for the util with uid matcher * Move the test to separate directory * Use goimports on the test file * Rename the test for a mroe matching name, add failing test * Update the regexp so that two letter work --------- Co-authored-by: Roman Kamyk <roman@kamyk.me>
This commit is contained in:
parent
0b2f08ad15
commit
310f147911
@ -3,5 +3,5 @@ package util
|
|||||||
import "regexp"
|
import "regexp"
|
||||||
|
|
||||||
var (
|
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])?$")
|
||||||
)
|
)
|
||||||
|
37
test/util/resource_name_test.go
Normal file
37
test/util/resource_name_test.go
Normal file
@ -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)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user