-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merge #37 into cyphar/filepath-securejoin:main
Aleksa Sarai (6): gha: use stable/oldstable go versions gha: compile-test for all supported Go versions gha: test older Go versions in CI deps: downgrade golang.org/x/sys requirement go: lower Go requirement to Go 1.18 tests: don't call testing.Testing() in mocks LGTMs: cyphar
- Loading branch information
Showing
15 changed files
with
362 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
//go:build linux && go1.20 | ||
|
||
// Copyright (C) 2024 SUSE LLC. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package securejoin | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
// wrapBaseError is a helper that is equivalent to fmt.Errorf("%w: %w"), except | ||
// that on pre-1.20 Go versions only errors.Is() works properly (errors.Unwrap) | ||
// is only guaranteed to give you baseErr. | ||
func wrapBaseError(baseErr, extraErr error) error { | ||
return fmt.Errorf("%w: %w", extraErr, baseErr) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
//go:build linux | ||
|
||
// Copyright (C) 2024 SUSE LLC. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package securejoin | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestGoCompatErrorWrap(t *testing.T) { | ||
baseErr := errors.New("base error") | ||
extraErr := errors.New("extra error") | ||
|
||
err := wrapBaseError(baseErr, extraErr) | ||
|
||
require.Error(t, err) | ||
assert.ErrorIs(t, err, baseErr, "wrapped error should contain base error") | ||
assert.ErrorIs(t, err, extraErr, "wrapped error should contain extra error") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
//go:build linux && !go1.20 | ||
|
||
// Copyright (C) 2024 SUSE LLC. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package securejoin | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
type wrappedError struct { | ||
inner error | ||
isError error | ||
} | ||
|
||
func (err wrappedError) Is(target error) bool { | ||
return err.isError == target | ||
} | ||
|
||
func (err wrappedError) Unwrap() error { | ||
return err.inner | ||
} | ||
|
||
func (err wrappedError) Error() string { | ||
return fmt.Sprintf("%v: %v", err.isError, err.inner) | ||
} | ||
|
||
// wrapBaseError is a helper that is equivalent to fmt.Errorf("%w: %w"), except | ||
// that on pre-1.20 Go versions only errors.Is() works properly (errors.Unwrap) | ||
// is only guaranteed to give you baseErr. | ||
func wrapBaseError(baseErr, extraErr error) error { | ||
return wrappedError{ | ||
inner: baseErr, | ||
isError: extraErr, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
//go:build linux && go1.21 | ||
|
||
// Copyright (C) 2024 SUSE LLC. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package securejoin | ||
|
||
import ( | ||
"slices" | ||
"sync" | ||
) | ||
|
||
func slices_DeleteFunc[S ~[]E, E any](slice S, delFn func(E) bool) S { | ||
return slices.DeleteFunc(slice, delFn) | ||
} | ||
|
||
func slices_Contains[S ~[]E, E comparable](slice S, val E) bool { | ||
return slices.Contains(slice, val) | ||
} | ||
|
||
func slices_Clone[S ~[]E, E any](slice S) S { | ||
return slices.Clone(slice) | ||
} | ||
|
||
func sync_OnceValue[T any](f func() T) func() T { | ||
return sync.OnceValue(f) | ||
} | ||
|
||
func sync_OnceValues[T1, T2 any](f func() (T1, T2)) func() (T1, T2) { | ||
return sync.OnceValues(f) | ||
} |
Oops, something went wrong.