git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2 3/4] ci/lib: do not interpret escape sequences in `group ()` arguments

From
Toon Claes <toon@iotcl.com>
Date
Dec 11, 2024, 12:37 UTC
Message-ID
<874j3ajsym.fsf@iotcl.com>
In-Reply-To
<20241210-pks-ci-section-fixes-v2-3-e087cfd174f4@pks.im>
Patrick Steinhardt <ps@pks.im> writes:
Show 5 quoted lines
> We use printf to set up sections with GitLab CI, which requires us to
> print a bunch of escape sequences via printf. The group name is
> controlled by the user and is expanded directly into the formatting
> string, which may cause problems in case the argument controls escape
> sequences or formatting directives.
Could it be you mean "contains" instead of "controls"?
Show 19 quoted lines
>
> Fix this potential issue by using formatting directives to pass variable
> data.
>
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
>  ci/lib.sh | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/ci/lib.sh b/ci/lib.sh
> index a54601be923bf475ba1a9cafd98bb1cb71a10255..f15f77f03a06120afbee438cee76ddc2683e1fa2 100755
> --- a/ci/lib.sh
> +++ b/ci/lib.sh
> @@ -18,7 +18,7 @@ elif test true = "$GITLAB_CI"
>  then
>  	begin_group () {
>  		need_to_end_group=t
> -		printf "\e[0Ksection_start:$(date +%s):$(echo "$1" | tr ' ' _)[collapsed=true]\r\e[0K$1\n"
> +		printf '\e[0Ksection_start:%s:%s[collapsed=true]\r\e[0K%s\n' "$(date +%s)" "$(echo "$1" | tr ' ' _)" "$1"

Personally I find this line rather lengthy and hard to read with all the single and double quotes. So I would suggest to split the line with a backslash and put the arguments on a separate line. But I don't think there's a general guideline on this, so feel free to ignore.

Show 9 quoted lines
>  		trap "end_group '$1'" EXIT
>  		set -x
>  	}
> @@ -27,7 +27,7 @@ then
>  		test -n "$need_to_end_group" || return 0
>  		set +x
>  		need_to_end_group=
> -		printf "\e[0Ksection_end:$(date +%s):$(echo "$1" | tr ' ' _)\r\e[0K\n"
> +		printf '\e[0Ksection_end:%s:%s\r\e[0K\n' "$(date +%s)" "$(echo "$1" | tr ' ' _)"
Same here.
But that's all I've got on this patch series. Looking good!

-- Toon

Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 18 of 20 in “Random improvements to GitLab CI”
  1. 0/4 Random improvements to GitLab CIPatrick Steinhardt, Dec 6, 2024
  2. 2/4 ci/lib: remove duplicate trap to end "CI setup" groupPatrick Steinhardt, Dec 6, 2024
  3. 1/4 gitlab-ci: update macOS images to SonomaPatrick Steinhardt, Dec 6, 2024
  4. karthik nayakDec 6, 2024
  5. Patrick SteinhardtDec 6, 2024
  6. karthik nayakDec 7, 2024
  7. 3/4 ci/lib: use echo instead of printf to set up sectionsPatrick Steinhardt, Dec 6, 2024
  8. Oswald BuddenhagenDec 7, 2024
  9. Patrick SteinhardtDec 10, 2024
  10. 4/4 ci/lib: fix "CI setup" sections with GitLab CIPatrick Steinhardt, Dec 6, 2024
  11. karthik nayakDec 6, 2024
  12. karthik nayakDec 6, 2024
  13. Patrick SteinhardtDec 6, 2024
  14. 0/4 Random improvements to GitLab CIPatrick Steinhardt, Dec 10, 2024
  15. 1/4 gitlab-ci: update macOS images to SonomaPatrick Steinhardt, Dec 10, 2024
  16. 2/4 ci/lib: remove duplicate trap to end "CI setup" groupPatrick Steinhardt, Dec 10, 2024
  17. 3/4 ci/lib: do not interpret escape sequences in `group ()` argumentsPatrick Steinhardt, Dec 10, 2024
  18. Toon ClaesDec 11, 2024
  19. Patrick SteinhardtDec 12, 2024
  20. 4/4 ci/lib: fix "CI setup" sections with GitLab CIPatrick Steinhardt, Dec 10, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.