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).
This commit is contained in:
Omar Polo 2022-11-29 23:24:21 +00:00
parent a057e3a49c
commit 4fbd4dcc6e
3 changed files with 22 additions and 1 deletions

10
ex.c
View File

@ -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);

View File

@ -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

View File

@ -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() {