diff --git a/go.mod b/go.mod index 589fe8c..4e19b40 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,6 @@ go 1.22 require ( github.com/s0rg/compflag v1.1.0 github.com/s0rg/set v1.2.0 - github.com/tdewolff/parse/v2 v2.7.14 - golang.org/x/net v0.26.0 + github.com/tdewolff/parse/v2 v2.7.15 + golang.org/x/net v0.27.0 ) diff --git a/go.sum b/go.sum index 1f80c0d..b9b745a 100644 --- a/go.sum +++ b/go.sum @@ -2,9 +2,9 @@ github.com/s0rg/compflag v1.1.0 h1:xhCUPLy+5Ue/Q9I/nIcLti2Ul6P42JYx4UvtYoDXmlQ= github.com/s0rg/compflag v1.1.0/go.mod h1:XMntVpc3+jpmBe0s8xo4w9swH8T9ARGkMC9HFiDRoUw= github.com/s0rg/set v1.2.0 h1:53b207YMktNQJXYei/oHuTR5oOO2e9+eieZOncYsh9g= github.com/s0rg/set v1.2.0/go.mod h1:xz3nDbjF4nyMLvAHvmE7rigXpNrKKTsi6iANznIB1/4= -github.com/tdewolff/parse/v2 v2.7.14 h1:100KJ+QAO3PpMb3uUjzEU/NpmCdbBYz6KPmCIAfWpR8= -github.com/tdewolff/parse/v2 v2.7.14/go.mod h1:3FbJWZp3XT9OWVN3Hmfp0p/a08v4h8J9W1aghka0soA= +github.com/tdewolff/parse/v2 v2.7.15 h1:hysDXtdGZIRF5UZXwpfn3ZWRbm+ru4l53/ajBRGpCTw= +github.com/tdewolff/parse/v2 v2.7.15/go.mod h1:3FbJWZp3XT9OWVN3Hmfp0p/a08v4h8J9W1aghka0soA= github.com/tdewolff/test v1.0.11-0.20231101010635-f1265d231d52 h1:gAQliwn+zJrkjAHVcBEYW/RFvd2St4yYimisvozAYlA= github.com/tdewolff/test v1.0.11-0.20231101010635-f1265d231d52/go.mod h1:6DAvZliBAAnD7rhVgwaM7DE5/d9NMOAJ09SqYqeK4QE= -golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ= -golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE= +golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys= +golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE= diff --git a/internal/crawler/crawler.go b/internal/crawler/crawler.go index 89e0a0a..0c10e9a 100644 --- a/internal/crawler/crawler.go +++ b/internal/crawler/crawler.go @@ -322,17 +322,20 @@ func (c *Crawler) process( } handleStatic := func(s string) { + var ok bool + switch { case strings.HasPrefix(s, doubleDash): - s = base.Scheme + s + s, ok = base.Scheme+s, true case strings.Contains(s, doubleDash): + ok = true default: - b, _ := url.Parse(uri) - r, _ := url.Parse(s) - s = b.ResolveReference(r).String() + s, ok = resolveRef(uri, s) } - c.staticHandler(s) + if ok { + c.staticHandler(s) + } } content := hdrs.Get(contentType) diff --git a/internal/crawler/util.go b/internal/crawler/util.go index 47457da..163ae2d 100644 --- a/internal/crawler/util.go +++ b/internal/crawler/util.go @@ -225,3 +225,19 @@ func urlhash(s string) (rv uint64) { return hash.Sum64() } + +func resolveRef(base, uri string) (rv string, ok bool) { + b, err := url.Parse(base) + if err != nil { + return + } + + u, err := url.Parse(uri) + if err != nil { + return + } + + rv = b.ResolveReference(u).String() + + return rv, true +}