💾 Archived View for gemi.dev › gemini-mailing-list › 000246.gmi captured on 2024-05-12 at 16:01:20. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2023-12-28)

-=-=-=-=-=-=-

Golang percent encoding

1. colecmac (a) protonmail.com (colecmac (a) protonmail.com)

Just wanted to let other Gemini Go coders know something about encoding
query strings. The Gemini spec mandates percent coding, so you should be
using url.PathEscape and url.PathUnescape to deal with queries, and NOT
url.QueryEscape and url.QueryUnescape.

However, there's one more thing. url.PathEscape does not replace +
characters, although to ensure compatibility, it probably should. Here's
the function I use in all my projects to escape queries:

func pathEscape(path string) string {
	return strings.ReplaceAll(url.PathEscape(path), "+", "%2B")
}

This is simple, but seems to work perfectly. url.PathUnescape will still
work fine for decoding.

Cheers,
makeworld

Link to individual message.

---

Previous Thread: Wikipedia through Gemini

Next Thread: [ANN] gemget v1.2.0