From aa15254e73d04916bead2f2743df55699987adac Mon Sep 17 00:00:00 2001 From: tjpcc Date: Tue, 10 Oct 2023 08:59:21 -0600 Subject: gofmt + allow finger requests without CRLF line ending --- finger/request.go | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) (limited to 'finger/request.go') diff --git a/finger/request.go b/finger/request.go index 5eae6b6..14058ca 100644 --- a/finger/request.go +++ b/finger/request.go @@ -13,18 +13,15 @@ import ( // ForwardingDenied is returned in response to requests for forwarding service. var ForwardingDenied = errors.New("Finger forwarding service denied.") -// InvalidFingerQuery is sent when a client doesn't properly format the query. -var InvalidFingerQuery = errors.New("Invalid finger query.") - // ParseRequest builds a sliderule.Request by reading a finger protocol request. // // At the time of writing, there is no firm standard on how to represent finger // queries as URLs (the finger protocol itself predates URLs entirely), but there // are a few helpful resources to go from. -// - The lynx browser supports finger URLs and documents the forms they may take: -// https://lynx.invisible-island.net/lynx_help/lynx_url_support.html#finger_url -// - There is an IETF draft: -// https://datatracker.ietf.org/doc/html/draft-ietf-uri-url-finger +// - The lynx browser supports finger URLs and documents the forms they may take: +// https://lynx.invisible-island.net/lynx_help/lynx_url_support.html#finger_url +// - There is an IETF draft: +// https://datatracker.ietf.org/doc/html/draft-ietf-uri-url-finger // // As this function builds a *sliderule.Request (which is mostly a wrapper around a URL) // from nothing but an io.Reader, it doesn't have the context of the hostname which @@ -53,13 +50,10 @@ func ParseRequest(rdr io.Reader) (*types.Request, error) { return nil, err } - if len(line) < 2 || line[len(line)-2] != '\r' { - return nil, InvalidFingerQuery - } - - line = strings.TrimSuffix(line, "\r\n") + line = strings.TrimRight(line, " \t\r\n") + line = strings.TrimLeft(line, " \t") line = strings.TrimPrefix(line, "/W") - line = strings.TrimLeft(line, " ") + line = strings.TrimLeft(line, " \t") username, hostname, _ := strings.Cut(line, "@") if strings.Contains(hostname, "@") { -- cgit v1.2.3