diff options
| author | Anhgelus Morhtuuzh <william@herges.fr> | 2026-03-15 14:22:15 +0100 |
|---|---|---|
| committer | Anhgelus Morhtuuzh <william@herges.fr> | 2026-03-15 14:22:15 +0100 |
| commit | 15cf6bb73408f9568c335be894d34372b5589a1d (patch) | |
| tree | 47acdb37eaa2f292411b3197b599ad928f22004e /human.go | |
| parent | 1ee4d17b20480b2d34ef289deab57fef77729b58 (diff) | |
feat(url): check match canonical
Diffstat (limited to 'human.go')
| -rw-r--r-- | human.go | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -23,6 +23,25 @@ var ( // URL represents a standard [url.URL] following normalization rules of human.json. type URL url.URL +func NewURL(s string) (*URL, error) { + raw, err := url.Parse(s) + if err != nil { + return nil, err + } + u := URL(*raw) + return &u, nil +} + +// Match returns true if url is within the scope. +// See https://codeberg.org/robida/human.json#url-matching. +func (u *URL) Match(url *URL) bool { + u.normalize() + url.normalize() + return u.Scheme == url.Scheme && + u.Host == url.Host && + (u.Path == url.Path || strings.HasPrefix(url.Path, u.Path+"/")) +} + func (u *URL) normalize() { if strings.Contains(u.Host, ":") { sp := strings.Split(u.Host, ":") |
