Skip to content

Commit 5ca0fba

Browse files
author
jcole-crowdstrike
committed
Updating regex pattern to handle unicode whitespaces.
Replacing the \s whitespace characters with normal spaces (" ") to prevent breaking on unicode whitespace characters (e.g., NBSP). Without this, if a branch name contains a unicode whitespace character that falls under \s, then the branch name will be truncated.
1 parent 7fbfc77 commit 5ca0fba

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

‎git/remote.py

+1-1
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,

‎test/test_remote.py

+15
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,21 @@ 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)
10051020

10061021
class TestTimeouts(TestBase):
10071022
@with_rw_repo("HEAD", bare=False)

0 commit comments

Comments
 (0)