refined-github icon indicating copy to clipboard operation
refined-github copied to clipboard

`linkify-code` links to incorrect url in search pages

Open altrisi opened this issue 3 years ago • 5 comments

Please ensure:

  • [X] The bug is caused by Refined GitHub. It doesn't happen if I disable the extension.
  • [X] The bug happens after clearing extension cache. The "Clear cache" button below can also be found at the bottom of the options page.

Example URLs

https://github.com/refined-github/refined-github/search?q=.rgh-minimize-upload-bar

Extension version

22.6.25

Browser(s) used

Firefox 101.0.1

Description

Clicking an issue number in a linkified reference in code in a search page will link you to https://issues/[number] instead of to the issue.

No console errors other than failing to get the hovercard when hovering over the link.

Include in this issue:

  • [ ] Screenshots/video/gif demonstrating the bug, if it’s visual
  • [ ] Console errors, if any

altrisi avatar Jun 28 '22 20:06 altrisi

Oof, might this be because the link appears on a page that is not “isRepo”?

fregante avatar Jun 29 '22 03:06 fregante

Due to:

https://github.com/refined-github/refined-github/blob/52e419f68a6388f9fd291491f2f9f76465e8be8d/source/features/linkify-code.tsx#L13

and the underlying:

https://github.com/refined-github/github-url-detection/blob/4bd3c831fc2d44b1a0378fe27f1fcab804939744/index.ts#L708

The core issue is this line, which excludes isRepoSearch from isRepo:

https://github.com/refined-github/github-url-detection/blob/4bd3c831fc2d44b1a0378fe27f1fcab804939744/index.ts#L325

introduced by https://github.com/refined-github/refined-github/issues/1638 a longass time ago 🙂 due to https://github.com/refined-github/refined-github/issues/1637, so some features now expect isRepo to exclude search pages

@/maintainers, thoughts? Maybe we can differentiate "is repo URL" from "has repo header"?

fregante avatar Jun 29 '22 04:06 fregante

Couldn't we simply check for isRepoSearch as a special case in getRepo? Unless there's other places where we'd have to handle that case too

cheap-glitch avatar Jun 29 '22 06:06 cheap-glitch

I suppose that would be a quick fix. 👍 However I still think we’re (maybe unnecessarily) conflating “is repo” with “has repo header”. Maybe that’s the new detection we need:

hasRepoHeader = isRepo && !isRepoSearch

fregante avatar Jun 29 '22 07:06 fregante

I think every single repo-related detection does not need to check isRepoSearch, except the generic isRepo.

In the extension however, every explicit isRepo means hasRepoHeader. Maybe we can forbid the use of isRepo in the extension, also because I always found it too broad to begin with. hasRepoHeader has clearer intentions.

fregante avatar Jun 29 '22 14:06 fregante

This was probably fixed by https://github.com/refined-github/github-url-detection/pull/131, the link now works!

fregante avatar Sep 13 '22 17:09 fregante