Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 82bb3bb

Browse filesBrowse files
authored
Merge pull request #1908 from DaveLak/fix-issue-1887
Fix `IndexError` in `GitConfigParser` When a Quoted Config Value Contains a Trailing New Line
2 parents fa2b2d6 + 1a0ab5b commit 82bb3bb
Copy full SHA for 82bb3bb

File tree

3 files changed

+11
-7
lines changed
Filter options

3 files changed

+11
-7
lines changed

‎fuzzing/fuzz-targets/fuzz_config.py

Copy file name to clipboardExpand all lines: fuzzing/fuzz-targets/fuzz_config.py
+2-6Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,8 @@ def TestOneInput(data):
3939
git_config.read()
4040
except (MissingSectionHeaderError, ParsingError, UnicodeDecodeError):
4141
return -1 # Reject inputs raising expected exceptions
42-
except (IndexError, ValueError) as e:
43-
if isinstance(e, IndexError) and "string index out of range" in str(e):
44-
# Known possibility that might be patched
45-
# See: https://github.com/gitpython-developers/GitPython/issues/1887
46-
pass
47-
elif isinstance(e, ValueError) and "embedded null byte" in str(e):
42+
except ValueError as e:
43+
if "embedded null byte" in str(e):
4844
# The `os.path.expanduser` function, which does not accept strings
4945
# containing null bytes might raise this.
5046
return -1

‎git/config.py

Copy file name to clipboardExpand all lines: git/config.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ def _read(self, fp: Union[BufferedReader, IO[bytes]], fpname: str) -> None:
452452
e = None # None, or an exception.
453453

454454
def string_decode(v: str) -> str:
455-
if v[-1] == "\\":
455+
if v and v.endswith("\\"):
456456
v = v[:-1]
457457
# END cut trailing escapes to prevent decode error
458458

‎test/test_config.py

Copy file name to clipboardExpand all lines: test/test_config.py
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,14 @@ def test_multi_line_config(self):
142142
)
143143
self.assertEqual(len(config.sections()), 23)
144144

145+
def test_config_value_with_trailing_new_line(self):
146+
config_content = b'[section-header]\nkey:"value\n"'
147+
config_file = io.BytesIO(config_content)
148+
config_file.name = "multiline_value.config"
149+
150+
git_config = GitConfigParser(config_file)
151+
git_config.read() # This should not throw an exception
152+
145153
def test_base(self):
146154
path_repo = fixture_path("git_config")
147155
path_global = fixture_path("git_config_global")

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.