aboutsummaryrefslogtreecommitdiff
path: root/query.go
diff options
context:
space:
mode:
authorAdnan Maolood <[email protected]>2020-11-27 22:26:22 -0500
committerAdnan Maolood <[email protected]>2020-11-27 22:27:52 -0500
commit16739d20d0c97162c2a19dc47a4fd4318aa12a7e (patch)
tree9794faa7c0afce6e53f97639766ae31c011b744f /query.go
parentexamples/server: Increase certificate duration (diff)
downloadgo-gemini-16739d20d0c97162c2a19dc47a4fd4318aa12a7e.tar.xz
go-gemini-16739d20d0c97162c2a19dc47a4fd4318aa12a7e.zip
Fix escaping of queries
Diffstat (limited to 'query.go')
-rw-r--r--query.go17
1 files changed, 17 insertions, 0 deletions
diff --git a/query.go b/query.go
new file mode 100644
index 0000000..3e80e8b
--- /dev/null
+++ b/query.go
@@ -0,0 +1,17 @@
+package gemini
+
+import (
+ "net/url"
+ "strings"
+)
+
+// QueryEscape properly escapes a string for use in a Gemini URL query.
+// It is like url.PathEscape except that it also replaces plus signs with their percent-encoded counterpart.
+func QueryEscape(query string) string {
+ return strings.ReplaceAll(url.PathEscape(query), "+", "%2B")
+}
+
+// QueryUnescape is identical to url.PathUnescape.
+func QueryUnescape(query string) (string, error) {
+ return url.PathUnescape(query)
+}