Skip to content

Commit 50202fd

Browse files
committed
Escape Windows path forward slashes in regex
1 parent 2adea72 commit 50202fd

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

tests/unit/test_req_file.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ def parse_reqfile(
7979
)
8080

8181

82+
def path_to_string(p: Path) -> str:
83+
# Escape the back slashes in windows path before using it
84+
# in a regex
85+
return str(p).replace("\\", "\\\\")
86+
87+
8288
def test_read_file_url(tmp_path: Path, session: PipSession) -> None:
8389
reqs = tmp_path.joinpath("requirements.txt")
8490
reqs.write_text("foo")
@@ -360,8 +366,8 @@ def test_recursive_requirements_file(
360366
with pytest.raises(
361367
RecursionError,
362368
match=(
363-
f"{req_files[0]} recursively references itself"
364-
f" in {req_files[req_file_count - 1]}"
369+
f"{path_to_string(req_files[0])} recursively references itself"
370+
f" in {path_to_string(req_files[req_file_count - 1])}"
365371
),
366372
):
367373
list(parse_requirements(filename=str(req_files[0]), session=session))
@@ -371,9 +377,10 @@ def test_recursive_requirements_file(
371377
with pytest.raises(
372378
RecursionError,
373379
match=(
374-
f"{req_files[req_file_count - 2]} recursively references itself "
375-
f"in {req_files[req_file_count - 1]} and again in"
376-
f" {req_files[req_file_count - 3]}"
380+
f"{path_to_string(req_files[req_file_count - 2])} recursively"
381+
" references itself in"
382+
f" {path_to_string(req_files[req_file_count - 1])} and again in"
383+
f" {path_to_string(req_files[req_file_count - 3])}"
377384
),
378385
):
379386
list(parse_requirements(filename=str(req_files[0]), session=session))
@@ -393,7 +400,8 @@ def test_recursive_relative_requirements_file(
393400
with pytest.raises(
394401
RecursionError,
395402
match=(
396-
f"{root_req_file} recursively references itself in {level_2_req_file}"
403+
f"{path_to_string(root_req_file)} recursively references itself in"
404+
f" {path_to_string(level_2_req_file)}"
397405
),
398406
):
399407
list(parse_requirements(filename=str(root_req_file), session=session))

0 commit comments

Comments
 (0)