commit 4fbd4dcc6ee14dc6b739f804cda650725b33c50a from: Omar Polo date: Tue Nov 29 23:24:21 2022 UTC 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). commit - a057e3a49c3d893382b0a6e19348bec3d8a4f819 commit + 4fbd4dcc6ee14dc6b739f804cda650725b33c50a blob - fbda0b5850083353a621bd68d3caaf3f8f0bf5c2 blob + 95e84a539a2bd12bbb1fccb7d056698ed084f1be --- ex.c +++ ex.c @@ -147,7 +147,7 @@ launch_cgi(struct iri *iri, struct cgireq *req, struct return -1; case 0: { /* child */ - char *ex, *pwd; + char *ex, *pwd, *qs; char iribuf[GEMINI_URL_LEN]; char path[PATH_MAX]; struct envlist *e; @@ -183,6 +183,14 @@ launch_cgi(struct iri *iri, struct cgireq *req, struct strlcat(path, "/", sizeof(path)); strlcat(path, req->relpath, sizeof(path)); 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); blob - d7e2e12aa6331b14655f151ffa73bd15a07ba7cf blob + 772c7e31caa6057bfa64ae775a5e0698d54e3280 --- regress/env +++ 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 blob - 6a30334a74bd5573dc6227b8218a924852f1cd15 blob + ac9e9a1010b55ad31643e358b6a6db638dfd0d77 --- regress/tests.sh +++ 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() {