~sotirisp/kindleto

38f34e06ca4ac1b63adf6285d4e387f72d4ad0a9 — Sotiris Papatheodorou 1 year, 11 months ago 5214175
Fix finger query parsing

Only decode space and slash.
1 files changed, 10 insertions(+), 9 deletions(-)

M finger/finger.go
M finger/finger.go => finger/finger.go +10 -9
@@ 22,18 22,18 @@ import (

const timeout = 15 * time.Second

func Proxy(w http.ResponseWriter, _ *http.Request, u *url.URL) error {
	var query string
func extractQuery(u *url.URL) string {
	if u.RawPath == "" {
		query = strings.TrimPrefix(u.Path, "/")
	} else {
		var err error
		query, err = url.PathUnescape(strings.TrimPrefix(u.RawPath, "/"))
		if err != nil {
			return fmt.Errorf("finger.Proxy: invalid URL-encoding in %v: %v", u, err)
		}
		return strings.TrimPrefix(u.Path, "/")
	}
	// Only decode space and slash, see the finger URL Specification:
	// https://datatracker.ietf.org/doc/html/draft-ietf-uri-url-finger
	query := strings.TrimPrefix(u.RawPath, "/")
	query = strings.ReplaceAll(query, "%20", " ")
	return strings.ReplaceAll(query, "%2F", "/")
}

func Proxy(w http.ResponseWriter, _ *http.Request, u *url.URL) error {
	address := u.Hostname() + ":"
	if u.Port() == "" {
		address += "79"


@@ 46,6 46,7 @@ func Proxy(w http.ResponseWriter, _ *http.Request, u *url.URL) error {
	}
	defer conn.Close()

	query := extractQuery(u)
	_, err = io.WriteString(conn, query+"\r\n")
	if err != nil {
		return fmt.Errorf("finger.Proxy: error sending query %s to %v: %v", query, u, err)