Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

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

Sign up
Appearance settings

FixIndexError inGitConfigParser When a Quoted Config Value Contains a Trailing New Line#1908

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Byron merged 3 commits intogitpython-developers:mainfromDaveLak:fix-issue-1887
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletionsfuzzing/fuzz-targets/fuzz_config.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -34,12 +34,8 @@ def TestOneInput(data):
git_config.read()
except (MissingSectionHeaderError, ParsingError, UnicodeDecodeError):
return -1 # Reject inputs raising expected exceptions
except (IndexError, ValueError) as e:
if isinstance(e, IndexError) and "string index out of range" in str(e):
# Known possibility that might be patched
# See: https://github.com/gitpython-developers/GitPython/issues/1887
pass
elif isinstance(e, ValueError) and "embedded null byte" in str(e):
except ValueError as e:
if "embedded null byte" in str(e):
# The `os.path.expanduser` function, which does not accept strings
# containing null bytes might raise this.
return -1
Expand Down
2 changes: 1 addition & 1 deletiongit/config.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -452,7 +452,7 @@ def _read(self, fp: Union[BufferedReader, IO[bytes]], fpname: str) -> None:
e = None # None, or an exception.

def string_decode(v: str) -> str:
if v[-1] =="\\":
if v and v.endswith("\\"):

This comment was marked as resolved.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Sorry, for some reason I didn't seethat comment! That addresses this proactively and my above comment can be disregarded entirely.

If the code is modified further in the future then thestr annotation, which is inconsistent with aNone value, could be examined and potentially changed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

By the way, I tried to enable branch protections which should enable auto-merge, and thus resolve the issue with long-running CI sometimes preventing a merge in addition to me forgetting to do it later. It didn't yet work for this PR, but I will see for the next one.

EliahKagan and DaveLak reacted with thumbs up emoji
v = v[:-1]
# END cut trailing escapes to prevent decode error

Expand Down
8 changes: 8 additions & 0 deletionstest/test_config.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -142,6 +142,14 @@ def test_multi_line_config(self):
)
self.assertEqual(len(config.sections()), 23)

def test_config_value_with_trailing_new_line(self):
config_content = b'[section-header]\nkey:"value\n"'
config_file = io.BytesIO(config_content)
config_file.name = "multiline_value.config"

git_config = GitConfigParser(config_file)
git_config.read() # This should not throw an exception

def test_base(self):
path_repo = fixture_path("git_config")
path_global = fixture_path("git_config_global")
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp