-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix tests failing on Go 1.20 on Windows. Clean works differently on 1.20. Use path.Clean instead with some workaround related to errors.
- Loading branch information
Showing
4 changed files
with
51 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
//go:build !windows | ||
|
||
package middleware | ||
|
||
import ( | ||
"os" | ||
) | ||
|
||
// We ignore these errors as there could be handler that matches request path. | ||
func isIgnorableOpenFileError(err error) bool { | ||
return os.IsNotExist(err) | ||
} |
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,23 @@ | ||
package middleware | ||
|
||
import ( | ||
"os" | ||
) | ||
|
||
// We ignore these errors as there could be handler that matches request path. | ||
// | ||
// As of Go 1.20 filepath.Clean has different behaviour on OS related filesystems so we need to use path.Clean | ||
// on Windows which has some caveats. The Open methods might return different errors than earlier versions and | ||
// as of 1.20 path checks are more strict on the provided path and considers [UNC](https://en.wikipedia.org/wiki/Path_(computing)#UNC) | ||
// paths with missing host etc parts as invalid. Previously it would result you `fs.ErrNotExist`. | ||
// | ||
// For 1.20@Windows we need to treat those errors the same as `fs.ErrNotExists` so we can continue handling | ||
// errors in the middleware/handler chain. Otherwise we might end up with status 500 instead of finding a route | ||
// or return 404 not found. | ||
func isIgnorableOpenFileError(err error) bool { | ||
if os.IsNotExist(err) { | ||
return true | ||
} | ||
errTxt := err.Error() | ||
return errTxt == "http: invalid or unsafe file path" || errTxt == "invalid path" | ||
} |