@@ -67,6 +67,11 @@ func mapOpenError(originalErr error, name string, sep rune, stat func(string) (f
67
67
return originalErr
68
68
}
69
69
70
+ // errInvalidUnsafePath is returned by Dir.Open when the call to
71
+ // filepath.Localize fails. filepath.Localize returns an error if the path
72
+ // cannot be represented by the operating system.
73
+ var errInvalidUnsafePath = errors .New ("http: invalid or unsafe file path" )
74
+
70
75
// Open implements [FileSystem] using [os.Open], opening files for reading rooted
71
76
// and relative to the directory d.
72
77
func (d Dir ) Open (name string ) (File , error ) {
@@ -76,7 +81,7 @@ func (d Dir) Open(name string) (File, error) {
76
81
}
77
82
path , err := filepath .Localize (path )
78
83
if err != nil {
79
- return nil , errors . New ( "http: invalid or unsafe file path" )
84
+ return nil , errInvalidUnsafePath
80
85
}
81
86
dir := string (d )
82
87
if dir == "" {
@@ -768,6 +773,9 @@ func toHTTPError(err error) (msg string, httpStatus int) {
768
773
if errors .Is (err , fs .ErrPermission ) {
769
774
return "403 Forbidden" , StatusForbidden
770
775
}
776
+ if errors .Is (err , errInvalidUnsafePath ) {
777
+ return "404 page not found" , StatusNotFound
778
+ }
771
779
// Default:
772
780
return "500 Internal Server Error" , StatusInternalServerError
773
781
}
0 commit comments