Skip to content

Commit 9bee003

Browse files
codexByron
authored andcommitted
Address review comment about unterminated subsection quotes
Review feedback: Section-name validation treated closing brackets as quoted data even when the opening quote was never closed or ended with a trailing escape. The tests also lacked those malformed quoted-subsection cases. Reject section names whose quote state remains open after scanning the complete name. Extend the existing writer-entry-point regression matrix with both an unterminated quoted subsection and one ending in a trailing escape, while retaining the valid quoted-bracket case.
1 parent ecd6844 commit 9bee003

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

git/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,8 @@ def _assure_config_name_safe(self, name: "cp._SectionName", label: str) -> None:
909909
in_quotes = not in_quotes
910910
elif char == "]" and not in_quotes:
911911
raise ValueError("Git config section names must not contain an unquoted closing bracket")
912+
if in_quotes:
913+
raise ValueError("Git config section names must not contain an unterminated quote")
912914

913915
@needs_values
914916
@set_dirty_and_flush_changes

test/test_config.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,21 +197,26 @@ def test_set_value_rejects_unsafe_section_and_option_names(self, rw_dir):
197197
@with_rw_directory
198198
def test_writer_rejects_unquoted_section_terminators(self, rw_dir):
199199
config_path = osp.join(rw_dir, "config")
200-
bad_sections = ("user] [other", 'submodule "docs"] [other')
200+
bad_sections = (
201+
"user] [other",
202+
'submodule "docs"] [other',
203+
'submodule "docs] [other',
204+
'submodule "docs] [other\\',
205+
)
201206
safe_section = 'submodule "docs]archive"'
202207

203208
with GitConfigParser(config_path, read_only=False) as git_config:
204209
git_config.add_section("user")
205210
for bad_section in bad_sections:
206-
with pytest.raises(ValueError, match="closing bracket"):
211+
with pytest.raises(ValueError, match="section name"):
207212
git_config.add_section(bad_section)
208-
with pytest.raises(ValueError, match="closing bracket"):
213+
with pytest.raises(ValueError, match="section name"):
209214
git_config.set(bad_section, "name", "value")
210-
with pytest.raises(ValueError, match="closing bracket"):
215+
with pytest.raises(ValueError, match="section name"):
211216
git_config.set_value(bad_section, "name", "value")
212-
with pytest.raises(ValueError, match="closing bracket"):
217+
with pytest.raises(ValueError, match="section name"):
213218
git_config.add_value(bad_section, "name", "value")
214-
with pytest.raises(ValueError, match="closing bracket"):
219+
with pytest.raises(ValueError, match="section name"):
215220
git_config.rename_section("user", bad_section)
216221

217222
git_config.set_value("user", "name", "safe")

0 commit comments

Comments
 (0)