Files
syft/internal/unknown/path_error_test.go
T
Alex Goodman 901d7bbab2 fix: don't infer archive nesting from paths in error text
`ProcessPathErrors` cut the `path="..."` it pulled out of an error at the first `!/` and built nested
coordinates from it, so a host file with `!/` in its name was reported as a file inside an archive.

- paths from error text are taken as plain real paths again, as on main
- the php extension reader already has the location in hand, so it records the unknown against that
  instead of re-parsing the error (this is the one caller that could see a nested path). It also
  no longer defers `Close` on a nil reader when the read fails

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
2026-10-21 11:28:53 -04:00

58 lines
1.3 KiB
Go

package unknown
import (
"fmt"
"testing"
"github.com/stretchr/testify/require"
"github.com/anchore/syft/syft/file"
)
func Test_ProcessPathErrors(t *testing.T) {
tests := []struct {
errorText string
expected error
}{
{
errorText: `prefix path="/var/lib/thing" suffix`,
expected: &CoordinateError{
Coordinates: file.NewCoordinates("/var/lib/thing", ""),
Reason: fmt.Errorf(`prefix path="/var/lib/thing" suffix`),
},
},
{
errorText: `prefix path="/var/lib/thing"`,
expected: &CoordinateError{
Coordinates: file.NewCoordinates("/var/lib/thing", ""),
Reason: fmt.Errorf(`prefix path="/var/lib/thing"`),
},
},
{
errorText: `path="/var/lib/thing" suffix`,
expected: &CoordinateError{
Coordinates: file.NewCoordinates("/var/lib/thing", ""),
Reason: fmt.Errorf(`path="/var/lib/thing" suffix`),
},
},
{
errorText: `path="/data/Hello!/world.txt"`,
expected: &CoordinateError{
Coordinates: file.NewCoordinates("/data/Hello!/world.txt", ""),
Reason: fmt.Errorf(`path="/data/Hello!/world.txt"`),
},
},
{
errorText: "all your base are belong to us",
expected: nil,
},
}
for _, test := range tests {
t.Run(test.errorText, func(t *testing.T) {
got := ProcessPathErrors(fmt.Errorf("%s", test.errorText))
require.Equal(t, test.expected, got)
})
}
}