Repository: raviqqe/muffet
Pull request #301 (2023-04-19 04:07:01)

Ignore text fragments
Temporary fix for #293.

codecov[bot]: ## [Codecov](https://codecov.io/gh/raviqqe/muffet/pull/301?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Yota+Toyama) Report
> Merging [#301](https://codecov.io/gh/raviqqe/muffet/pull/301?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Yota+Toyama) (6df13bb) into [main](https://codecov.io/gh/raviqqe/muffet/commit/9cd738f25a8e2fcd06be01f513b3be1b18daaadd?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Yota+Toyama) (9cd738f) will **not change** coverage.
> The diff coverage is `100.00%`.

> :exclamation: Current head 6df13bb differs from pull request most recent head a5b1e2c. Consider uploading reports for the commit a5b1e2c to get more accurate results

```diff
@@           Coverage Diff           @@
##             main     #301   +/-   ##
=======================================
  Coverage   87.89%   87.89%           
=======================================
  Files          27       27           
  Lines         785      785           
=======================================
  Hits          690      690           
  Misses         77       77           
  Partials       18       18           
```


| [Impacted Files](https://codecov.io/gh/raviqqe/muffet/pull/301?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Yota+Toyama) | Coverage Δ | |
|---|---|---|
| [link\_fetcher.go](https://codecov.io/gh/raviqqe/muffet/pull/301?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Yota+Toyama#diff-bGlua19mZXRjaGVyLmdv) | `78.26% <100.00%> (ø)` | |

:mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Yota+Toyama)


Patch:
diff --git a/link_fetcher.go b/link_fetcher.go
index 59b6799..dafe9e3 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)


Test patch:
diff --git a/link_fetcher_test.go b/link_fetcher_test.go
index 8695f8e..d332e6b 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) {