mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 16:33:21 +01:00
source: when base is set, responsePath should be absolute (#1542)
When base is set, it should appear identically to when we scan the root filesystem - and as a result, the path should begin with the path separator. E.g. when scanning the root `./target/` with the same base, `target/bin/busybox` should appear in the output as `/bin/busybox`, not as previously as `bin/busybox`. Signed-off-by: Justin Chadwell <me@jedevc.com>
This commit is contained in:
parent
9995950c70
commit
6ba595344a
@ -330,12 +330,19 @@ func (r directoryResolver) responsePath(path string) string {
|
|||||||
path = posixToWindows(path)
|
path = posixToWindows(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
// always return references relative to the request path (not absolute path)
|
// clean references to the request path (either the root, or the base if set)
|
||||||
if filepath.IsAbs(path) {
|
if filepath.IsAbs(path) {
|
||||||
// we need to account for the cwd relative to the running process and the given root for the directory resolver
|
var prefix string
|
||||||
prefix := filepath.Clean(filepath.Join(r.currentWd, r.currentWdRelativeToRoot))
|
if r.base != "" {
|
||||||
return strings.TrimPrefix(path, prefix+string(filepath.Separator))
|
prefix = r.base
|
||||||
|
} else {
|
||||||
|
// we need to account for the cwd relative to the running process and the given root for the directory resolver
|
||||||
|
prefix = filepath.Clean(filepath.Join(r.currentWd, r.currentWdRelativeToRoot))
|
||||||
|
prefix += string(filepath.Separator)
|
||||||
|
}
|
||||||
|
path = strings.TrimPrefix(path, prefix)
|
||||||
}
|
}
|
||||||
|
|
||||||
return path
|
return path
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -898,7 +898,7 @@ func TestDirectoryResolver_FilesByPath_baseRoot(t *testing.T) {
|
|||||||
root: "./test-fixtures/symlinks-base/",
|
root: "./test-fixtures/symlinks-base/",
|
||||||
input: "./base",
|
input: "./base",
|
||||||
expected: []string{
|
expected: []string{
|
||||||
"base",
|
"/base",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -906,7 +906,7 @@ func TestDirectoryResolver_FilesByPath_baseRoot(t *testing.T) {
|
|||||||
root: "./test-fixtures/symlinks-base/",
|
root: "./test-fixtures/symlinks-base/",
|
||||||
input: "./foo",
|
input: "./foo",
|
||||||
expected: []string{
|
expected: []string{
|
||||||
"base",
|
"/base",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -914,7 +914,7 @@ func TestDirectoryResolver_FilesByPath_baseRoot(t *testing.T) {
|
|||||||
root: "./test-fixtures/symlinks-base/",
|
root: "./test-fixtures/symlinks-base/",
|
||||||
input: "./bar",
|
input: "./bar",
|
||||||
expected: []string{
|
expected: []string{
|
||||||
"base",
|
"/base",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -922,7 +922,7 @@ func TestDirectoryResolver_FilesByPath_baseRoot(t *testing.T) {
|
|||||||
root: "./test-fixtures/symlinks-base/",
|
root: "./test-fixtures/symlinks-base/",
|
||||||
input: "./baz",
|
input: "./baz",
|
||||||
expected: []string{
|
expected: []string{
|
||||||
"base",
|
"/base",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -930,7 +930,7 @@ func TestDirectoryResolver_FilesByPath_baseRoot(t *testing.T) {
|
|||||||
root: "./test-fixtures/symlinks-base/",
|
root: "./test-fixtures/symlinks-base/",
|
||||||
input: "./sub/link",
|
input: "./sub/link",
|
||||||
expected: []string{
|
expected: []string{
|
||||||
"sub/item",
|
"/sub/item",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -938,7 +938,7 @@ func TestDirectoryResolver_FilesByPath_baseRoot(t *testing.T) {
|
|||||||
root: "./test-fixtures/symlinks-base/",
|
root: "./test-fixtures/symlinks-base/",
|
||||||
input: "./chain",
|
input: "./chain",
|
||||||
expected: []string{
|
expected: []string{
|
||||||
"base",
|
"/base",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user