From b3abb1aab96a10eab977097898f3e51b3e84d0e8 Mon Sep 17 00:00:00 2001 From: Brendan Collins Date: Tue, 12 May 2026 11:22:30 -0700 Subject: [PATCH] Fix VRT path-rejection error format on Windows The ValueError emitted by parse_vrt for paths outside the VRT directory used {filename!r} and {vrt_root!r}, which on Windows renders backslashes as doubled escapes (C:\\\\Users\\\\...). That broke test_error_message_names_rejected_path on the windows-latest runner since the assertion compares against the raw os.path.realpath output. The same doubled-escape output is also user-hostile on Windows. Switch to explicit single-quote interpolation for filename and vrt_root so the rendered path uses single backslashes. allowed_roots stays as !r since it is a list, and the list-of-strings repr is fine cross-platform. --- xrspatial/geotiff/_vrt.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/xrspatial/geotiff/_vrt.py b/xrspatial/geotiff/_vrt.py index 5319d4a8..534d09b2 100644 --- a/xrspatial/geotiff/_vrt.py +++ b/xrspatial/geotiff/_vrt.py @@ -300,9 +300,15 @@ def parse_vrt(xml_str: str, vrt_dir: str = '.') -> VRTDataset: else: trusted = [vrt_root, *allowed_roots] if not any(_path_is_under(filename, r) for r in trusted): + # Use direct interpolation (not !r) for ``filename`` and + # ``vrt_root`` so Windows paths render with single + # backslashes rather than the doubled escapes repr emits. + # The explicit quotes keep the boundary readable when the + # path has embedded spaces. ``allowed_roots`` stays as !r + # for its list-of-strings render. raise ValueError( - f"VRT SourceFilename {filename!r} resolves outside " - f"the VRT directory ({vrt_root!r}) and is not " + f"VRT SourceFilename '{filename}' resolves outside " + f"the VRT directory ('{vrt_root}') and is not " f"covered by any {_ALLOWED_ROOTS_ENV} entry " f"({allowed_roots!r}). Refusing to read; see issue " f"#1671."