Protect canonical operand prefixes from aliases
This commit is contained in:
11
registry.go
11
registry.go
@@ -326,7 +326,7 @@ func traceCanonicalPath(roots map[string]*canonicalNode, path commandpath.Path)
|
||||
continue
|
||||
}
|
||||
operandCount := len(path) - index
|
||||
if current != nil && acceptsOperandCount(current.command, operandCount) {
|
||||
if current != nil && acceptsOperandPrefix(current.command, operandCount) {
|
||||
return commandAliasTrace{operandOwner: current}
|
||||
}
|
||||
return commandAliasTrace{}
|
||||
@@ -334,14 +334,15 @@ func traceCanonicalPath(roots map[string]*canonicalNode, path commandpath.Path)
|
||||
return commandAliasTrace{exact: current}
|
||||
}
|
||||
|
||||
func acceptsOperandCount(command Command, count int) bool {
|
||||
// acceptsOperandPrefix reports whether more operands could complete this prefix.
|
||||
// A source need not already satisfy the command's minimum to intercept it.
|
||||
func acceptsOperandPrefix(command Command, count int) bool {
|
||||
if command.record == nil || command.record.payload == nil || !command.record.payload.hasRun() {
|
||||
return false
|
||||
}
|
||||
arguments := command.record.payload.bridgeArguments()
|
||||
minimum, maximum := 0, 0
|
||||
maximum := 0
|
||||
for _, argument := range arguments {
|
||||
minimum += argument.Min
|
||||
if maximum >= 0 {
|
||||
if argument.Max < 0 {
|
||||
maximum = -1
|
||||
@@ -350,5 +351,5 @@ func acceptsOperandCount(command Command, count int) bool {
|
||||
}
|
||||
}
|
||||
}
|
||||
return count >= minimum && (maximum < 0 || count <= maximum)
|
||||
return maximum < 0 || count <= maximum
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user