From 83bc5a7c589a5c655a777ffd3197c24ee5506e90 Mon Sep 17 00:00:00 2001 From: Mohammed Al Sahaf Date: Sat, 27 Feb 2021 01:49:50 +0300 Subject: [PATCH] accept replacements with branches of github forks (#51) * accept replacements with branches of github forks Closes #50 * remove `!filepath.IsAbs(repl)` when checking path of replacement If the replacement path starts with a `.`, then the path is definitely not absolute. --- cmd/xcaddy/main.go | 10 +++++++--- cmd/xcaddy/main_test.go | 11 +++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/cmd/xcaddy/main.go b/cmd/xcaddy/main.go index 001f462..0be38b5 100644 --- a/cmd/xcaddy/main.go +++ b/cmd/xcaddy/main.go @@ -76,7 +76,7 @@ func runBuild(ctx context.Context, args []string) error { }) if repl != "" { // adjust relative replacements in current working directory since our temporary module is in a different directory - if !filepath.IsAbs(repl) { + if strings.HasPrefix(repl, ".") { repl, err = filepath.Abs(repl) if err != nil { log.Fatalf("[FATAL] %v", err) @@ -288,9 +288,13 @@ func trapSignals(ctx context.Context, cancel context.CancelFunc) { func splitWith(arg string) (module, version, replace string, err error) { const versionSplit, replaceSplit = "@", "=" - parts := strings.SplitN(arg, versionSplit, 2) - module = parts[0] + modules := strings.SplitN(arg, replaceSplit, 2) + if len(modules) > 1 { + replace = modules[1] + } + parts := strings.SplitN(modules[0], versionSplit, 2) + module = parts[0] if len(parts) == 1 { parts := strings.SplitN(module, replaceSplit, 2) if len(parts) > 1 { diff --git a/cmd/xcaddy/main_test.go b/cmd/xcaddy/main_test.go index 63800c0..c3b7d3a 100644 --- a/cmd/xcaddy/main_test.go +++ b/cmd/xcaddy/main_test.go @@ -33,6 +33,17 @@ func TestSplitWith(t *testing.T) { expectModule: "module", expectReplace: "replace", }, + { + input: "module=replace@version", + expectModule: "module", + expectReplace: "replace@version", + }, + { + input: "module@version=replace@version", + expectModule: "module", + expectVersion: "version", + expectReplace: "replace@version", + }, { input: "=replace", expectErr: true,