mirror of
https://github.com/bitechdev/ResolveSpec.git
synced 2026-01-20 09:34:27 +00:00
fix(staticweb): add nil check to WithStripPrefix helper
Prevent panic when WithStripPrefix is called with a nil provider by using reflection to check for typed nil pointers stored in interfaces.
This commit is contained in:
@@ -3,6 +3,7 @@ package staticweb
|
|||||||
import (
|
import (
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"reflect"
|
||||||
)
|
)
|
||||||
|
|
||||||
// FileSystemProvider abstracts the source of files (local, zip, embedded, future: http, s3)
|
// FileSystemProvider abstracts the source of files (local, zip, embedded, future: http, s3)
|
||||||
@@ -51,7 +52,10 @@ type PrefixStrippingProvider interface {
|
|||||||
// WithStripPrefix is a helper function that sets the strip prefix on a provider
|
// WithStripPrefix is a helper function that sets the strip prefix on a provider
|
||||||
// if it implements PrefixStrippingProvider. Returns the provider for method chaining.
|
// if it implements PrefixStrippingProvider. Returns the provider for method chaining.
|
||||||
func WithStripPrefix(provider FileSystemProvider, prefix string) FileSystemProvider {
|
func WithStripPrefix(provider FileSystemProvider, prefix string) FileSystemProvider {
|
||||||
if p, ok := provider.(PrefixStrippingProvider); ok {
|
if provider == nil || reflect.ValueOf(provider).IsNil() {
|
||||||
|
return provider
|
||||||
|
}
|
||||||
|
if p, ok := provider.(PrefixStrippingProvider); ok && p != nil {
|
||||||
p.WithStripPrefix(prefix)
|
p.WithStripPrefix(prefix)
|
||||||
}
|
}
|
||||||
return provider
|
return provider
|
||||||
|
|||||||
Reference in New Issue
Block a user