Fix matching of lazygit-edit URLs without line numbers

Tweak regexp such that a trailing ":" is not included in the file path
extracted from a lazygit-edit URL.

Previously, when matching a URL containing the ":" separator but no line
number, such as `lazygit-edit:///path/to/file.ext:`, the trailing
separator would be included in the matched file path, so lazygit would
open the non-existent file `/path/to/file.ext:`. Notably, such urls are
created when using delta with the hyperlink feature, as suggested in
https://github.com/jesseduffield/lazygit/blob/master/docs/Custom_Pagers.md#delta,
and clicking a file path rather than a line number.
This commit is contained in:
Daniel Wennberg 2026-02-19 15:57:49 -08:00 committed by Stefan Haller
parent f8676ffa5e
commit 8821770711

View file

@ -377,7 +377,7 @@ func (gui *Gui) onNewRepo(startArgs appTypes.StartArgs, contextKey types.Context
gui.g.SetOpenHyperlinkFunc(func(url string, viewname string) error {
if strings.HasPrefix(url, "lazygit-edit:") {
re := regexp.MustCompile(`^lazygit-edit://(.+?)(?::(\d+))?$`)
re := regexp.MustCompile(`^lazygit-edit://(.+?)(?::(\d*))?$`)
matches := re.FindStringSubmatch(url)
if matches == nil {
return fmt.Errorf(gui.Tr.InvalidLazygitEditURL, url)