Skip to content

Commit d40e7d0

Browse files
authored
Merge pull request #1853 from jcole-crowdstrike/fix-branch-name-regex-to-handle-nbsp
Update regex pattern to handle unicode whitespaces.
2 parents 12c139c + 8b8c76a commit d40e7d0

File tree

3 files changed

+20
-18
lines changed

3 files changed

+20
-18
lines changed

git/remote.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ class FetchInfo(IterableObj):
325325
ERROR,
326326
) = [1 << x for x in range(8)]
327327

328-
_re_fetch_result = re.compile(r"^\s*(.) (\[[\w\s\.$@]+\]|[\w\.$@]+)\s+(.+) -> ([^\s]+)( \(.*\)?$)?")
328+
_re_fetch_result = re.compile(r"^ *(.) (\[[\w \.$@]+\]|[\w\.$@]+) +(.+) -> ([^ ]+)( \(.*\)?$)?")
329329

330330
_flag_map: Dict[flagKeyLiteral, int] = {
331331
"!": ERROR,
@@ -895,7 +895,7 @@ def _get_fetch_info_from_stderr(
895895
None,
896896
progress_handler,
897897
finalizer=None,
898-
decode_streams=False,
898+
decode_streams=True,
899899
kill_after_timeout=kill_after_timeout,
900900
)
901901

@@ -1072,7 +1072,7 @@ def fetch(
10721072
Git.check_unsafe_options(options=list(kwargs.keys()), unsafe_options=self.unsafe_git_fetch_options)
10731073

10741074
proc = self.repo.git.fetch(
1075-
"--", self, *args, as_process=True, with_stdout=False, universal_newlines=True, v=verbose, **kwargs
1075+
"--", self, *args, as_process=True, with_stdout=False, universal_newlines=False, v=verbose, **kwargs
10761076
)
10771077
res = self._get_fetch_info_from_stderr(proc, progress, kill_after_timeout=kill_after_timeout)
10781078
if hasattr(self.repo.odb, "update_cache"):
@@ -1126,7 +1126,7 @@ def pull(
11261126
Git.check_unsafe_options(options=list(kwargs.keys()), unsafe_options=self.unsafe_git_pull_options)
11271127

11281128
proc = self.repo.git.pull(
1129-
"--", self, refspec, with_stdout=False, as_process=True, universal_newlines=True, v=True, **kwargs
1129+
"--", self, refspec, with_stdout=False, as_process=True, universal_newlines=False, v=True, **kwargs
11301130
)
11311131
res = self._get_fetch_info_from_stderr(proc, progress, kill_after_timeout=kill_after_timeout)
11321132
if hasattr(self.repo.odb, "update_cache"):

git/util.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -611,20 +611,6 @@ def _parse_progress_line(self, line: AnyStr) -> None:
611611
self.error_lines.append(self._cur_line)
612612
return
613613

614-
# Find escape characters and cut them away - regex will not work with
615-
# them as they are non-ASCII. As git might expect a tty, it will send them.
616-
last_valid_index = None
617-
for i, c in enumerate(reversed(line_str)):
618-
if ord(c) < 32:
619-
# its a slice index
620-
last_valid_index = -i - 1
621-
# END character was non-ASCII
622-
# END for each character in line
623-
if last_valid_index is not None:
624-
line_str = line_str[:last_valid_index]
625-
# END cut away invalid part
626-
line_str = line_str.rstrip()
627-
628614
cur_count, max_count = None, None
629615
match = self.re_op_relative.match(line_str)
630616
if match is None:

test/test_remote.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,22 @@ def test_push_unsafe_options_allowed(self, rw_repo):
10021002
assert tmp_file.exists()
10031003
tmp_file.unlink()
10041004

1005+
@with_rw_and_rw_remote_repo("0.1.6")
1006+
def test_fetch_unsafe_branch_name(self, rw_repo, remote_repo):
1007+
# Create branch with a name containing a NBSP
1008+
bad_branch_name = f"branch_with_{chr(160)}_nbsp"
1009+
Head.create(remote_repo, bad_branch_name)
1010+
1011+
# Fetch and get branches
1012+
remote = rw_repo.remote("origin")
1013+
branches = remote.fetch()
1014+
1015+
# Test for truncated branch name in branches
1016+
assert f"origin/{bad_branch_name}" in [b.name for b in branches]
1017+
1018+
# Cleanup branch
1019+
Head.delete(remote_repo, bad_branch_name)
1020+
10051021

10061022
class TestTimeouts(TestBase):
10071023
@with_rw_repo("HEAD", bare=False)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy