tpope/vim-fugitive

[bug] `'<,'>GBrowse` attaches `%5C` in URL before the `#` character

Opened this issue · 4 comments

after this commit, and because of this line the # character used to point to a specific line/range of lines is escaped, causing the opened URL to look like this: <path_to_file>%5C#<lines> which results in 404 Not Found error. Confirmed this by removing the escape() call from the mentioned line and re-building neovim

A possible fix would be to use netrw#Open() if available, and update the escaping to match. That way older versions of Vim can still work with the old behavior of netrw#BrowseX().

fortunately, most of the escaping in netrw#BrowseX doesn't seem to actually be applied to the url in this case. I think that checking if has('nvim-<version>') && exists('*netrw#Open') can be sufficient enough
i.e.

diff --git a/autoload/fugitive.vim b/autoload/fugitive.vim
index 17fd04d..9dba547 100644
--- a/autoload/fugitive.vim
+++ b/autoload/fugitive.vim
@@ -7437,7 +7437,9 @@ function! s:BrowserOpen(url, mods, echo_copy) abort
     if !exists('g:loaded_netrw')
       runtime! autoload/netrw.vim
     endif
-    if exists('*netrw#BrowseX')
+    if has('nvim-0.11') && exists('*netrw#Open')
+      return 'echo '.string(url).'|' . mods . 'call netrw#Open('.string(url).')'
+    elseif exists('*netrw#BrowseX')
       return 'echo '.string(url).'|' . mods . 'call netrw#BrowseX('.string(url).', 0)'
     elseif exists('*netrw#NetrwBrowseX')
       return 'echo '.string(url).'|' . mods . 'call netrw#NetrwBrowseX('.string(url).', 0)'

The same happens with vim v9.1.906 on Fedora 41.

Im also affected by this as I have a custom browse handler with # in the URL https://github.com/sluongng/dotfiles/blob/aae4e38389defc08b7e97745fda9836cb39e2ce5/config/nvim/init.lua#L551-L556

Would love to get the PR merged