◐ Shell
clean mode source ↗

Validate config key names before writing by Byron · Pull Request #2142 · gitpython-developers/GitPython

AI review requested due to automatic review settings

May 5, 2026 13:44

Copilot AI review requested due to automatic review settings

May 5, 2026 13:56
GitConfigParser already rejected CR, LF, and NUL in config values before
writing, but section and option names could still reach configparser. Because
GitPython writes section headers itself, a newline-bearing section name could
split the output into additional headers.

Reject CR, LF, and NUL in section and option names on write paths that create
or set config keys: add_section(), set(), set_value(), add_value(), and
rename_section() destinations. This matches Git config key validation behavior;
Git source commit 94f057755b7941b321fd11fec1b2e3ca5313a4e0 reports invalid keys
containing newlines from config.c, and local git 2.50.1 rejects newline-bearing
config keys.

Add a regression test covering unsafe section and option names while preserving
safe writes.

Co-authored-by: Sebastian Thiel <sebastian.thiel@icloud.com>