From bb523c9542e2848dfa403d0d84c759ad771e9d69 Mon Sep 17 00:00:00 2001 From: Jes Cok Date: Thu, 28 Mar 2024 22:33:37 +0800 Subject: net/http: correct doc for ServeFileFS The documentation of ServeFileFS was partly copied from ServeFile in CL 513956, however it's not exact. This CL fixes some typos, also removes obsolete comment for name param. For consistency, also adds godoc link for ServeFile and ServeContent. Fixes #66578 Change-Id: I87147d72c533d46284f06ef20b37fdafa8706710 Reviewed-on: https://go-review.googlesource.com/c/go/+/575016 Reviewed-by: Than McIntosh LUCI-TryBot-Result: Go LUCI Reviewed-by: Damien Neil Reviewed-by: Mauri de Souza Meneguzzo --- src/net/http/fs.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/net/http/fs.go b/src/net/http/fs.go index 45cf16eed1..25e9406a58 100644 --- a/src/net/http/fs.go +++ b/src/net/http/fs.go @@ -747,7 +747,7 @@ func localRedirect(w ResponseWriter, r *Request, newPath string) { // If the provided file or directory name is a relative path, it is // interpreted relative to the current directory and may ascend to // parent directories. If the provided name is constructed from user -// input, it should be sanitized before calling ServeFile. +// input, it should be sanitized before calling [ServeFile]. // // As a precaution, ServeFile will reject requests where r.URL.Path // contains a ".." path element; this protects against callers who @@ -779,22 +779,20 @@ func ServeFile(w ResponseWriter, r *Request, name string) { // ServeFileFS replies to the request with the contents // of the named file or directory from the file system fsys. // -// If the provided file or directory name is a relative path, it is -// interpreted relative to the current directory and may ascend to -// parent directories. If the provided name is constructed from user -// input, it should be sanitized before calling [ServeFile]. +// If the provided name is constructed from user input, it should be +// sanitized before calling [ServeFileFS]. // -// As a precaution, ServeFile will reject requests where r.URL.Path +// As a precaution, ServeFileFS will reject requests where r.URL.Path // contains a ".." path element; this protects against callers who // might unsafely use [filepath.Join] on r.URL.Path without sanitizing // it and then use that filepath.Join result as the name argument. // -// As another special case, ServeFile redirects any request where r.URL.Path +// As another special case, ServeFileFS redirects any request where r.URL.Path // ends in "/index.html" to the same path, without the final // "index.html". To avoid such redirects either modify the path or -// use ServeContent. +// use [ServeContent]. // -// Outside of those two special cases, ServeFile does not use +// Outside of those two special cases, ServeFileFS does not use // r.URL.Path for selecting the file or directory to serve; only the // file or directory provided in the name argument is used. func ServeFileFS(w ResponseWriter, r *Request, fsys fs.FS, name string) { -- cgit v1.2.3-54-g00ecf