From 6ebe62790a02e1d302cd1836a262e5b31ab35047 Mon Sep 17 00:00:00 2001 From: casjay Date: Wed, 5 Aug 2026 01:51:13 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20=5F=5Fformat=5Fvariables?= =?UTF-8?q?=20returning=20a=20single=20space=20for=20empty=20input=20?= =?UTF-8?q?=F0=9F=90=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit App-breaking bug found during full runtime verification of the act_runner cache-server feature: gitea failed to start with `Command error: unknown command: /config/gitea/app.ini` because its `--port` argument was empty. Root cause: `__format_variables()` ran `printf '%s\n' $input | sort -Ru | tr '\n' ' '` unconditionally. When `$input` word-splits to zero words (whitespace-only, e.g. no port env vars set), `printf` with a `%s` format still runs once with a missing arg, emitting a blank line — so the function returned a single space `" "` instead of empty. That made `ENV_PORTS` / `WEB_SERVER_PORTS` resolve to `" "`, which made `SERVICE_PORT` in `08-gitea.sh` become `" "` — non-empty per `[ -n ... ]` but rendering as an empty `--port` value to `gitea web`. - rootfs/usr/local/etc/docker/functions/entrypoint.sh: replaced `[ -z "$input" ] && return 0` with `[[ "$input" =~ [^[:space:]] ]] || return 0` so whitespace-only input is treated as empty before reaching the `printf` pipeline - TODO.AI.md: logged the fix and the upstream-template-sync follow-up Verified: rebuilt the image and confirmed `gitea will be running on port 80` / `gitea web --port 80 ...` in a full container run (previously `--port` with no value). --- TODO.AI.md | 13 +++++++++++++ rootfs/usr/local/etc/docker/functions/entrypoint.sh | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/TODO.AI.md b/TODO.AI.md index a8b09f8..c69ad53 100644 --- a/TODO.AI.md +++ b/TODO.AI.md @@ -29,6 +29,19 @@ Update Runbook in AI.md — `functions/entrypoint.sh` is normally regenerated, n - `__random_password()` (~line 333): `tr | head -c` pipeline died under `set -eo pipefail` on SIGPIPE. Fixed by wrapping in `{ ... } || true`. +## App-breaking bug fixed — __format_variables() whitespace-only input (functions/entrypoint.sh) + +Needs syncing back to the upstream template per AI.md's runbook. + +- `__format_variables()` (~line 187): `printf '%s\n' $input | sort -Ru | tr '\n' ' '` always + emits at least one line even when `$input` word-splits to zero words (whitespace-only), because + `printf` with a format containing `%s` runs once even with no args. This made `ENV_PORTS` / + `WEB_SERVER_PORTS` resolve to a single space `" "` instead of empty when no port env vars were + set, which made `SERVICE_PORT` in `08-gitea.sh` become `" "` — passing the `-n` test but + rendering as an empty `--port` arg to `gitea web`, which broke gitea's CLI argument parsing + entirely (`Command error: unknown command: /config/gitea/app.ini`). Fixed by replacing the + `[ -z "$input" ]` check with `[[ "$input" =~ [^[:space:]] ]] || return 0`. + ## Other observations not yet actioned - `.gitea/workflows/docker.yaml` uses the same stale/unpinned action pattern (`@v2`-`@v4`, DockerHub-only, `catthehacker/ubuntu:act-latest`) that was removed from the `opengist` repo's duplicate workflow — no `build.yml` counterpart exists here yet. diff --git a/rootfs/usr/local/etc/docker/functions/entrypoint.sh b/rootfs/usr/local/etc/docker/functions/entrypoint.sh index 738315a..263836a 100644 --- a/rootfs/usr/local/etc/docker/functions/entrypoint.sh +++ b/rootfs/usr/local/etc/docker/functions/entrypoint.sh @@ -186,7 +186,7 @@ __get_pid() { # - - - - - - - - - - - - - - - - - - - - - - - - - __format_variables() { local input="${*//,/ }" - [ -z "$input" ] && return 0 + [[ "$input" =~ [^[:space:]] ]] || return 0 printf '%s\n' $input | sort -Ru | tr '\n' ' ' } # - - - - - - - - - - - - - - - - - - - - - - - - -