Skip to content

bug: gitbrowse prepends a second scheme to http:// remotes #2954

Description

@meleu

Did you check docs and existing issues?

  • I have read all the snacks.nvim docs
  • I have updated the plugin to the latest version before submitting this issue
  • I have searched the existing issues of snacks.nvim
  • I have searched the existing issues of plugins related to this issue

Neovim version (nvim -v)

NVIM v0.12.5, LuaJIT 2.1.1788460057

Operating system/version

Arch Linux

Describe the bug

For a repository whose remote uses plain http:// (e.g.: self-hosted GitLab instances on an internal network), Snacks.gitbrowse() opens an invalid URL with two schemes glued together:

remote: http://git.example.com/group/subgroup/repo.git
opened: https://http://git.example.com/group/subgroup/repo

The cause is in M.get_repo() (lua/snacks/gitbrowse.lua:96):

return ret:find("https://") == 1 and ret or ("https://%s"):format(ret)

Although the remote_patterns loop handles http correctly with { "^(https?://.*)%.git$", "%1" }, the final scheme check only recognizes https://. Therefore, an http URL that already has a scheme is treated as schemeless and gets https:// prepended.

No error is shown; the notification and the browser both receive the malformed URL.

Steps To Reproduce

  1. Create a repo with a plain-http remote:
mkdir /tmp/gitbrowse-http && cd /tmp/gitbrowse-http
git init -q .
printf 'line1\nline2\nline3\n' > README.md
git add README.md && git commit -qm init
git remote add origin http://git.example.com/group/subgroup/repo.git
  1. Open the file: nvim README.md
  2. Type <leader>gY and then paste.
  3. The printed URL is https://http://git.example.com/group/subgroup/repo

Expected Behavior

In the example above, I expect to see http://git.example.com/group/subgroup/repo

Repro

vim.env.LAZY_STDPATH = ".repro"
load(vim.fn.system("curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua"))()

require("lazy.minit").repro({
  spec = {
    { "folke/snacks.nvim", opts = {} },
    -- add any other plugins here
  },
})

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions