mirror of
https://github.com/caddyserver/xcaddy.git
synced 2025-01-22 08:36:28 +01:00
Tolerate module file paths with @ in them
But version must also be specified to disambiguate. Fix #109
This commit is contained in:
parent
47f9ded5d8
commit
7577d60f61
2 changed files with 19 additions and 15 deletions
28
cmd/main.go
28
cmd/main.go
|
@ -343,25 +343,23 @@ func trapSignals(ctx context.Context, cancel context.CancelFunc) {
|
|||
func splitWith(arg string) (module, version, replace string, err error) {
|
||||
const versionSplit, replaceSplit = "@", "="
|
||||
|
||||
modules := strings.SplitN(arg, replaceSplit, 2)
|
||||
if len(modules) > 1 {
|
||||
replace = modules[1]
|
||||
parts := strings.SplitN(arg, replaceSplit, 2)
|
||||
if len(parts) > 1 {
|
||||
replace = parts[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 {
|
||||
module = parts[0]
|
||||
replace = parts[1]
|
||||
|
||||
// accommodate module paths that have @ in them, but we can only tolerate that if there's also
|
||||
// a version, otherwise we don't know if it's a version separator or part of the file path (see #109)
|
||||
lastVersionSplit := strings.LastIndex(module, versionSplit)
|
||||
if lastVersionSplit < 0 {
|
||||
if replaceIdx := strings.Index(module, replaceSplit); replaceIdx >= 0 {
|
||||
module, replace = module[:replaceIdx], module[replaceIdx+1:]
|
||||
}
|
||||
} else {
|
||||
version = parts[1]
|
||||
parts := strings.SplitN(version, replaceSplit, 2)
|
||||
if len(parts) > 1 {
|
||||
version = parts[0]
|
||||
replace = parts[1]
|
||||
module, version = module[:lastVersionSplit], module[lastVersionSplit+1:]
|
||||
if replaceIdx := strings.Index(version, replaceSplit); replaceIdx >= 0 {
|
||||
version, replace = module[:replaceIdx], module[replaceIdx+1:]
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -60,6 +60,12 @@ func TestSplitWith(t *testing.T) {
|
|||
input: "",
|
||||
expectErr: true,
|
||||
},
|
||||
{
|
||||
// issue #109
|
||||
input: "/home/devin/projects/@relay/caddy-bin@version",
|
||||
expectModule: "/home/devin/projects/@relay/caddy-bin",
|
||||
expectVersion: "version",
|
||||
},
|
||||
} {
|
||||
actualModule, actualVersion, actualReplace, actualErr := splitWith(tc.input)
|
||||
if actualModule != tc.expectModule {
|
||||
|
|
Loading…
Reference in a new issue