Initial commit
Test / test (push) Successful in 7m5s
Release / gates (push) Successful in 7m28s
Release / build (amd64, freebsd) (push) Successful in 2m52s
Release / build (amd64, linux) (push) Successful in 2m46s
Release / build (arm64, freebsd) (push) Successful in 2m22s
Release / build (arm64, linux) (push) Successful in 2m38s
Release / build (loong64, linux) (push) Successful in 2m7s
Release / build (riscv64, linux) (push) Successful in 2m17s
Release / release (push) Successful in 1m0s
Test / test (push) Successful in 7m5s
Release / gates (push) Successful in 7m28s
Release / build (amd64, freebsd) (push) Successful in 2m52s
Release / build (amd64, linux) (push) Successful in 2m46s
Release / build (arm64, freebsd) (push) Successful in 2m22s
Release / build (arm64, linux) (push) Successful in 2m38s
Release / build (loong64, linux) (push) Successful in 2m7s
Release / build (riscv64, linux) (push) Successful in 2m17s
Release / release (push) Successful in 1m0s
Assisted-by: GLM 5.3
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
// Copyright (c) 2026 Petr Balvín <opensource@petrbalvin.org> (https://petrbalvin.org)
|
||||
// SPDX-License-Identifier: PolyForm-Noncommercial-1.0.0
|
||||
|
||||
// Package fediverse validates the fediverse handle that posts, users and
|
||||
// the site configuration carry. It is a leaf so that the configuration
|
||||
// and the domain object can share one rule without either importing the
|
||||
// other.
|
||||
package fediverse
|
||||
|
||||
import "regexp"
|
||||
|
||||
var handleRe = regexp.MustCompile(`\A@[^@\s]+@[^@\s]+\z`)
|
||||
|
||||
// Valid reports whether handle looks like @user@host.
|
||||
func Valid(handle string) bool {
|
||||
return handleRe.MatchString(handle)
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
// Copyright (c) 2026 Petr Balvín <opensource@petrbalvin.org> (https://petrbalvin.org)
|
||||
// SPDX-License-Identifier: PolyForm-Noncommercial-1.0.0
|
||||
|
||||
package fediverse
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestValid(t *testing.T) {
|
||||
good := []string{"@user@host.social", "@a@b", "@petr@social.example.org"}
|
||||
for _, handle := range good {
|
||||
if !Valid(handle) {
|
||||
t.Errorf("Valid(%q) = false, want true", handle)
|
||||
}
|
||||
}
|
||||
bad := []string{"", "user@host", "@user", "@@host", "@user@", "@user @host", "@user@ho st", "u@h"}
|
||||
for _, handle := range bad {
|
||||
if Valid(handle) {
|
||||
t.Errorf("Valid(%q) = true, want false", handle)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user