diff --git a/link_fetcher.go b/link_fetcher.go index 59b67992..dafe9e3b 100644 --- a/link_fetcher.go +++ b/link_fetcher.go @@ -33,7 +33,8 @@ func (f *linkFetcher) Fetch(u string) (int, *page, error) { s, p, err := f.sendRequestWithCache(u) if err != nil { return 0, nil, err - } else if p == nil || f.options.IgnoreFragments || fr == "" { + } else if p == nil || f.options.IgnoreFragments || fr == "" || strings.HasPrefix(fr, ":~:") { + // TODO Support text fragments. return s, p, nil } else if _, ok := p.Fragments()[fr]; !ok { return 0, nil, fmt.Errorf("id #%v not found", fr) diff --git a/link_fetcher_test.go b/link_fetcher_test.go index 8695f8e3..d332e6b0 100644 --- a/link_fetcher_test.go +++ b/link_fetcher_test.go @@ -144,6 +144,24 @@ func TestLinkFetcherFetchIgnoringFragments(t *testing.T) { assert.Nil(t, err) } +func TestLinkFetcherFetchSkippingTextFragment(t *testing.T) { + s := "http://foo.com" + f := newTestLinkFetcher( + newFakeHttpClient( + func(u *url.URL) (*fakeHttpResponse, error) { + if u.String() != s { + return nil, errors.New("") + } + + return newFakeHtmlResponse(s, ""), nil + }, + ), + ) + + _, _, err := f.Fetch(s + "#:~:text=foo") + assert.Nil(t, err) +} + func TestLinkFetcherFailToFetch(t *testing.T) { f := newTestLinkFetcher( newFakeHttpClient(func(*url.URL) (*fakeHttpResponse, error) {