mirror of
https://github.com/anchore/syft.git
synced 2026-11-02 23:46:35 +01:00
fix: Make the fileresolver Support Prefix Match of Files (#3820)
* fix the dpkg files pattern detection Signed-off-by: Yuntao Hu <victorhu493@gmail.com> * consider slash before the path is concatenated Signed-off-by: Yuntao Hu <victorhu493@gmail.com> * add test Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> --------- Signed-off-by: Yuntao Hu <victorhu493@gmail.com> Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> Co-authored-by: Alex Goodman <wagoodman@users.noreply.github.com>
This commit is contained in:
co-authored by
Alex Goodman
parent
5c6c6aa123
commit
9af087d213
@@ -169,7 +169,11 @@ func (r ChrootContext) ToNativeGlob(chrootPath string) (string, error) {
|
||||
return "", err
|
||||
}
|
||||
|
||||
parts[0] = strings.TrimRight(responsePath, "/") + "/"
|
||||
hasSlash := strings.HasSuffix(parts[0], "/")
|
||||
parts[0] = responsePath
|
||||
if hasSlash {
|
||||
parts[0] = strings.TrimRight(parts[0], "/") + "/"
|
||||
}
|
||||
|
||||
return strings.Join(parts, "*"), nil
|
||||
}
|
||||
|
||||
@@ -558,6 +558,16 @@ func TestToNativeGlob(t *testing.T) {
|
||||
expectedResult: "/cwd/relative/path/**/file*.txt",
|
||||
expectedError: nil,
|
||||
},
|
||||
{
|
||||
name: "ending with glob",
|
||||
chrootContext: ChrootContext{
|
||||
root: "/root",
|
||||
cwdRelativeToRoot: "/cwd",
|
||||
},
|
||||
chrootPath: "/var/lib/dpkg/info/name.*",
|
||||
expectedResult: "/root/var/lib/dpkg/info/name.*",
|
||||
expectedError: nil,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
||||
Reference in New Issue
Block a user