`git config` fails in CI if the user's name contains certain (maybe non-ASCII?) characters

Summary

When user name contains a white space and some Japanese/Chinese (and probably other) characters, git config command can fail on CI.

Steps to reproduce

  1. Set the current user name to contain a white space and certain characters (the precise range is not clear, but I've confirmed that Chinese/Japanese characters such as 里 are problematic).
  2. Set up a CI/CD to run a command git config --global user.name $GITLAB_USER_NAME
  3. Run the CI job

Example Project

https://gitlab.com/BanzaiMan/ci-tester

What is the current bug behavior?

https://gitlab.com/BanzaiMan/ci-tester/-/jobs/1238833541

The git config command fails and emits a help message:

[32;1m$ git config --global user.name $GITLAB_USER_NAME[0;m
usage: git config [<options>]

Config file location
    --global              use global config file
    --system              use system config file
    --local               use repository config file
    --worktree            use per-worktree config file
    -f, --file <file>     use given config file
    --blob <blob-id>      read config from given blob object

What is the expected correct behavior?

Command succeeds.

With only non-Latin (probably) characters, it succeeds https://gitlab.com/BanzaiMan/ci-tester/-/jobs/1238826597, and with only Latin and whitespace(s) it succeeds https://gitlab.com/BanzaiMan/ci-tester/-/jobs/1238821449.

Relevant logs and/or screenshots

See above.

Output of checks

This bug happens on GitLab.com

Possible fixes

Removing offending characters will solve the problem, but it seems wrong. I suspect there is some escaping and so on that needs to be done, but I don't know enough about GitLab's internals.

Edited by Hiro Asari