Skip to content

Commit

Permalink
Ignore text fragments (#301)
Browse files Browse the repository at this point in the history
Temporary fix for #293.
  • Loading branch information
raviqqe authored Apr 19, 2023
1 parent 9cd738f commit 10550e0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion link_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 18 additions & 0 deletions link_fetcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 10550e0

Please sign in to comment.