Commit e226e42
Validate config key names before writing
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.
Validation:
- uv run --with gitdb --with pytest --with pytest-cov --with ddt --with pytest-mock --with pytest-instafail --with pytest-sugar python -m pytest test/test_config.py::TestBase::test_set_value_rejects_unsafe_section_and_option_names --no-cov
- uv run --with gitdb --with pytest --with pytest-cov --with ddt --with pytest-mock --with pytest-instafail --with pytest-sugar python -m pytest test/test_config.py --no-cov
- uv run --with ruff ruff check git/config.py test/test_config.py
- codex review --uncommitted1 parent b7f5fde commit e226e42
2 files changed
Lines changed: 33 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
75 | 78 | | |
76 | 79 | | |
77 | 80 | | |
| |||
778 | 781 | | |
779 | 782 | | |
780 | 783 | | |
| 784 | + | |
781 | 785 | | |
782 | 786 | | |
783 | 787 | | |
| |||
888 | 892 | | |
889 | 893 | | |
890 | 894 | | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
891 | 899 | | |
892 | 900 | | |
893 | 901 | | |
| |||
896 | 904 | | |
897 | 905 | | |
898 | 906 | | |
| 907 | + | |
| 908 | + | |
899 | 909 | | |
900 | 910 | | |
901 | 911 | | |
| |||
920 | 930 | | |
921 | 931 | | |
922 | 932 | | |
| 933 | + | |
| 934 | + | |
923 | 935 | | |
924 | 936 | | |
925 | 937 | | |
| |||
948 | 960 | | |
949 | 961 | | |
950 | 962 | | |
| 963 | + | |
| 964 | + | |
951 | 965 | | |
952 | 966 | | |
953 | 967 | | |
| |||
968 | 982 | | |
969 | 983 | | |
970 | 984 | | |
| 985 | + | |
971 | 986 | | |
972 | 987 | | |
973 | 988 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
163 | 163 | | |
164 | 164 | | |
165 | 165 | | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
166 | 184 | | |
167 | 185 | | |
168 | 186 | | |
| |||
0 commit comments