aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOmar Polo <op@omarpolo.com>2022-11-29 23:24:21 +0000
committerOmar Polo <op@omarpolo.com>2022-11-29 23:24:21 +0000
commit4fbd4dcc6ee14dc6b739f804cda650725b33c50a (patch)
tree18d6acd48444dab5a7885c97a8061384ee31fd26
parenta057e3a49c3d893382b0a6e19348bec3d8a4f819 (diff)
define GEMINI_SEARCH_STRING for CGI scripts too
it's redundant since gmid already fills the script argv with the words extracted from the search string, but 2.0 won't have cgi support and not all fastcgi <-> cgi wrappers follow RFC3875 ยง 4.4. This can help in preparing scripts for a future when they'll be run under for e.g. slowcgi(8).
-rw-r--r--ex.c10
-rwxr-xr-xregress/env1
-rw-r--r--regress/tests.sh12
3 files changed, 22 insertions, 1 deletions
diff --git a/ex.c b/ex.c
index fbda0b5..95e84a5 100644
--- a/ex.c
+++ b/ex.c
@@ -147,7 +147,7 @@ launch_cgi(struct iri *iri, struct cgireq *req, struct vhost *vhost,
return -1;
case 0: { /* child */
- char *ex, *pwd;
+ char *ex, *pwd, *qs;
char iribuf[GEMINI_URL_LEN];
char path[PATH_MAX];
struct envlist *e;
@@ -185,6 +185,14 @@ launch_cgi(struct iri *iri, struct cgireq *req, struct vhost *vhost,
safe_setenv("PATH_TRANSLATED", path);
}
+ if (iri->query != NULL &&
+ strchr(iri->query, '=') == NULL &&
+ (qs = strdup(iri->query)) != NULL) {
+ pct_decode_str(qs);
+ safe_setenv("GEMINI_SEARCH_STRING", qs);
+ free(qs);
+ }
+
safe_setenv("QUERY_STRING", iri->query);
safe_setenv("REMOTE_ADDR", req->addr);
safe_setenv("REMOTE_HOST", req->addr);
diff --git a/regress/env b/regress/env
index d7e2e12..772c7e3 100755
--- a/regress/env
+++ b/regress/env
@@ -30,6 +30,7 @@ echo PWD=$PWD
echo PATH_INFO=${PATH_INFO:-"<unspec>"}
echo PATH_TRANSLATED=${PATH_TRANSLATED:-"<unspec>"}
echo QUERY_STRING=$QUERY_STRING
+echo GEMINI_SEARCH_STRING=${GEMINI_SEARCH_STRING:-"<unspec>"}
echo REMOTE_ADDR=$REMOTE_ADDR
echo REMOTE_HOST=$REMOTE_HOST
echo REQUEST_METHOD=$REQUEST_METHOD
diff --git a/regress/tests.sh b/regress/tests.sh
index 6a30334..ac9e9a1 100644
--- a/regress/tests.sh
+++ b/regress/tests.sh
@@ -145,6 +145,18 @@ test_cgi_split_query() {
return 1
fi
done
+
+ if ! n="$(get "/env?foo+bar%3d5" | grep GEMINI_SEARCH_STRING)"; then
+ echo "failed to get /env"
+ return 1
+ fi
+
+ if [ "$n" != "GEMINI_SEARCH_STRING=foo bar=5" ]; then
+ echo "wrong value for GEMINI_SEARCH_STRING"
+ echo "want : foo bar=5"
+ echo "got : $n"
+ return 1
+ fi
}
test_custom_index() {