mirror of
https://github.com/bitechdev/ResolveSpec.git
synced 2026-01-07 12:24:26 +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 (
|
||||
"io/fs"
|
||||
"net/http"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
// 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
|
||||
// if it implements PrefixStrippingProvider. Returns the provider for method chaining.
|
||||
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)
|
||||
}
|
||||
return provider
|
||||
|
||||
Reference in New Issue
Block a user