aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2017-07-11 22:00:45 -1000
committercel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2017-07-11 22:00:45 -1000
commitf599b16ec561ce29ad009d70c3e205cacf633be4 (patch)
treedb83f8419a610e2256a3c96f723d11497950d146
parentb3f11f34bc8aa544d2a1e9eeab6c56638983ec3b (diff)
url-decode search query
-rw-r--r--gopher.filter.dpi.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/gopher.filter.dpi.c b/gopher.filter.dpi.c
index 27eb489..faef30b 100644
--- a/gopher.filter.dpi.c
+++ b/gopher.filter.dpi.c
@@ -1,6 +1,7 @@
#include <err.h>
#include <errno.h>
#include <stdarg.h>
+#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
@@ -422,11 +423,22 @@ static void render_image(int s, const char *url) {
static void fix_path(char *path) {
char *query, *start, *end;
+ char buf[3];
/* change form input name to query */
start = query = strstr(path, "__gopher__query__=");
if (!start) return;
end = start + 18;
- while ((*start++ = *end++));
+ while (*end) {
+ if (*end == '%') {
+ strncpy(buf, end + 1, 2);
+ *start++ = strtoul(buf, NULL, 16);
+ end += 2;
+ }
+ else if (*end == '+') *start++ = ' ';
+ else *start++ = *end;
+ end++;
+ }
+ *start = '\0';
query[-1] = '\t';
}