+8
-6
appview/state/userutil/userutil.go
+8
-6
appview/state/userutil/userutil.go
···
5
"strings"
6
)
7
8
func IsHandleNoAt(s string) bool {
9
// ref: https://atproto.com/specs/handle
10
-
re := regexp.MustCompile(`^([a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?$`)
11
-
return re.MatchString(s)
12
}
13
14
func UnflattenDid(s string) string {
···
29
// Reconstruct as a standard DID format using Replace
30
// Example: "did-plc-xyz-abc" becomes "did:plc:xyz-abc"
31
reconstructed := strings.Replace(s, "-", ":", 2)
32
-
re := regexp.MustCompile(`^did:[a-z]+:[a-zA-Z0-9._:%-]*[a-zA-Z0-9._-]$`)
33
34
-
return re.MatchString(reconstructed)
35
}
36
37
// FlattenDid converts a DID to a flattened format.
···
46
47
// IsDid checks if the given string is a standard DID.
48
func IsDid(s string) bool {
49
-
re := regexp.MustCompile(`^did:[a-z]+:[a-zA-Z0-9._:%-]*[a-zA-Z0-9._-]$`)
50
-
return re.MatchString(s)
51
}
···
5
"strings"
6
)
7
8
+
var (
9
+
handleRegex = regexp.MustCompile(`^([a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?$`)
10
+
didRegex = regexp.MustCompile(`^did:[a-z]+:[a-zA-Z0-9._:%-]*[a-zA-Z0-9._-]$`)
11
+
)
12
+
13
func IsHandleNoAt(s string) bool {
14
// ref: https://atproto.com/specs/handle
15
+
return handleRegex.MatchString(s)
16
}
17
18
func UnflattenDid(s string) string {
···
33
// Reconstruct as a standard DID format using Replace
34
// Example: "did-plc-xyz-abc" becomes "did:plc:xyz-abc"
35
reconstructed := strings.Replace(s, "-", ":", 2)
36
37
+
return didRegex.MatchString(reconstructed)
38
}
39
40
// FlattenDid converts a DID to a flattened format.
···
49
50
// IsDid checks if the given string is a standard DID.
51
func IsDid(s string) bool {
52
+
return didRegex.MatchString(s)
53
}
+2
-1
flake.nix
+2
-1
flake.nix