diff --git a/internal/fsurls/fsurls.go b/internal/fsurls/fsurls.go index c9e1cc5..bb4af0e 100644 --- a/internal/fsurls/fsurls.go +++ b/internal/fsurls/fsurls.go @@ -682,18 +682,34 @@ func isURLIgnored(u string, patterns []string) bool { if len(patterns) == 0 { return false } - for _, p := range patterns { + for _, raw := range patterns { + p := strings.TrimSpace(raw) if p == "" { continue } - // simple contains or wildcard suffix/prefix match - if p == u || strings.Contains(u, p) { + // No wildcards: exact or substring match + if !strings.ContainsAny(p, "*?") { + if u == p || strings.Contains(u, p) { + return true + } + continue + } + // Glob-style: allow '*' to span slashes by converting '*' -> '**' + dsPat := strings.ReplaceAll(p, "*", "**") + if ok, _ := doublestar.PathMatch(dsPat, u); ok { return true } - // doublestar path-like match for full URL string - if ok, _ := doublestar.PathMatch(p, u); ok { + // Regex fallback: '*' -> '.*', '?' -> '.' + if re, err := wildcardToRegex(p); err == nil && re.MatchString(u) { return true } } return false } + +func wildcardToRegex(pattern string) (*regexp.Regexp, error) { + escaped := regexp.QuoteMeta(pattern) + escaped = strings.ReplaceAll(escaped, "\\*", ".*") + escaped = strings.ReplaceAll(escaped, "\\?", ".") + return regexp.Compile("^" + escaped + "$") +} diff --git a/internal/fsurls/fsurls_test.go b/internal/fsurls/fsurls_test.go index 79dd8eb..de6ae81 100644 --- a/internal/fsurls/fsurls_test.go +++ b/internal/fsurls/fsurls_test.go @@ -57,6 +57,17 @@ func TestCollectURLs_FromTestFiles(t *testing.T) { t.Fatalf("expected API URL %s to be ignored via .slinkignore", u) } } + // URLs matching *acme* should be ignored + acmeSamples := []string{ + "https://acme.com/logout", + "http://sub.acme.example/logout", + "https://docs.acme.dev", + } + for _, u := range acmeSamples { + if _, ok := urls[u]; ok { + t.Fatalf("expected %s to be ignored via *acme* pattern", u) + } + } // Verify .slinkignore path ignores: file under ignore-me should not contribute for u, files := range urls { diff --git a/testdata/test2_acme.md b/testdata/test2_acme.md new file mode 100644 index 0000000..323d314 --- /dev/null +++ b/testdata/test2_acme.md @@ -0,0 +1,5 @@ +Here are some example URLs that should be ignored by pattern *acme*: + +- https://acme.com/logout +- http://sub.acme.example/logout +- https://docs.acme.dev