Skip to content

Commit 861b5e4

Browse files
spoorccben-edna
authored andcommitted
Review comments
1 parent 5a876c8 commit 861b5e4

4 files changed

Lines changed: 20 additions & 8 deletions

File tree

dfetch/util/cmdline.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ def run_on_cmdline(
4949
except subprocess.CalledProcessError as exc:
5050
raise SubprocessCommandError(
5151
exc.cmd,
52-
exc.output.decode().strip(),
53-
exc.stderr.decode().strip(),
52+
exc.output.decode(errors="replace").strip(),
53+
exc.stderr.decode(errors="replace").strip(),
5454
exc.returncode,
5555
) from exc
5656
except FileNotFoundError as exc:
@@ -62,7 +62,10 @@ def run_on_cmdline(
6262

6363
if proc.returncode:
6464
raise SubprocessCommandError(
65-
cmd, stdout.decode(), stderr.decode().strip(), proc.returncode
65+
cmd,
66+
stdout.decode(errors="replace"),
67+
stderr.decode(errors="replace").strip(),
68+
proc.returncode,
6669
)
6770

6871
return proc

dfetch/vcs/archive.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -387,13 +387,12 @@ def check_zip_members(zf: zipfile.ZipFile) -> list[zipfile.ZipInfo]:
387387

388388
@staticmethod
389389
def _is_unsafe_symlink_target(target: str) -> bool:
390-
r"""Return *True* when *target* is an absolute symlink destination.
390+
r"""Return *True* when *target* is an unsafe symlink destination.
391391
392392
Absolute targets (POSIX ``/`` or Windows drive/UNC anchors) are
393-
always unsafe regardless of context. Relative targets that contain
394-
``..`` components are NOT rejected here; they are validated after
395-
extraction by :meth:`_check_symlinks_in_dest` using the manifest
396-
root as the safety boundary.
393+
always unsafe. Relative targets containing ``..`` components are
394+
permitted at pre-extraction time; :meth:`_check_symlinks_in_dest`
395+
enforces the boundary after extraction.
397396
"""
398397
posix = pathlib.PurePosixPath(target)
399398
win = pathlib.PureWindowsPath(target)

features/fetch-archive.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,3 +254,4 @@ Feature: Fetching dependencies from an archive (tar/zip)
254254
link.mk
255255
dfetch.yaml
256256
"""
257+
And 'MyProject/SomeProject/sub/dir/link.mk' is a symlink pointing to '../../other/target.mk'

features/steps/generic_steps.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,15 @@ def step_impl(_, name):
363363
assert os.path.exists(name), f"Expected {name} to exist, but it didn't!"
364364

365365

366+
@then("'{path}' is a symlink pointing to '{target}'")
367+
def step_impl(_, path, target):
368+
assert os.path.islink(
369+
path
370+
), f"Expected {path!r} to be a symbolic link, but it is not"
371+
actual = os.readlink(path)
372+
assert actual == target, f"Expected {path!r} to point to {target!r}, got {actual!r}"
373+
374+
366375
def multisub(patterns: List[Tuple[Pattern[str], str]], text: str) -> str:
367376
"""Apply a list of tuples that each contain a regex + replace string."""
368377
for pattern, replace in patterns:

0 commit comments

Comments
 (0)