diff --git a/src/python/pants/util/strutil.py b/src/python/pants/util/strutil.py index b44009691c8..776e0d532a5 100644 --- a/src/python/pants/util/strutil.py +++ b/src/python/pants/util/strutil.py @@ -139,7 +139,7 @@ def strip_v2_chroot_path(v: bytes | str) -> str: """ if isinstance(v, bytes): v = v.decode() - return re.sub(r"/.*/pants-sandbox-[a-zA-Z0-9]+/", "", v) + return re.sub(r"/[a-zA-Z0-9-_\/]*/pants-sandbox-[a-zA-Z0-9]+/", "", v) @dataclasses.dataclass(frozen=True) diff --git a/src/python/pants/util/strutil_test.py b/src/python/pants/util/strutil_test.py index c4e37b2aff2..67217de1ff1 100644 --- a/src/python/pants/util/strutil_test.py +++ b/src/python/pants/util/strutil_test.py @@ -114,6 +114,18 @@ def test_strip_chroot_path() -> None: assert strip_v2_chroot_path("") == "" assert strip_v2_chroot_path("hello world") == "hello world" + # Confirm other data (e.g. URLS) is unaffected + assert ( + strip_v2_chroot_path("https://pantsbuild.org and /private/tmp/pants-sandbox-uPH7bl/sandbox") + == "https://pantsbuild.org and sandbox" + ) + assert ( + strip_v2_chroot_path( + "{'URL': 'https://pantsbuild.org', 'VENV': '/tmp/q_dt/pants-sandbox-K3/.cache/pex'}" + ) + == "{'URL': 'https://pantsbuild.org', 'VENV': '.cache/pex'}" + ) + @pytest.mark.parametrize( ("strip_chroot_path", "strip_formatting", "expected"),