From 4fbd4dcc6ee14dc6b739f804cda650725b33c50a Mon Sep 17 00:00:00 2001 From: Omar Polo Date: Tue, 29 Nov 2022 23:24:21 +0000 Subject: [PATCH] define GEMINI_SEARCH_STRING for CGI scripts too MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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). --- ex.c | 10 +++++++++- regress/env | 1 + regress/tests.sh | 12 ++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) 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:-""} echo PATH_TRANSLATED=${PATH_TRANSLATED:-""} echo QUERY_STRING=$QUERY_STRING +echo GEMINI_SEARCH_STRING=${GEMINI_SEARCH_STRING:-""} 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() {