Skip to content

scrubbers rejects PathLike values and crashes on Windows paths #148

In review

Description

@tony

Summary

ScrubberSpec only accepts tuple[str | re.Pattern[str], str] and compiles every str pattern directly with re.compile(pat). Callers scrubbing pytest tmp_path directories cannot pass (tmp_path, "<TMP>") directly as an os.PathLike[str], and passing (str(tmp_path), "<TMP>") crashes on Windows paths (C:\Users\...) with re.PatternError and misinterprets regex metacharacters (such as [case0] or c++ directory segments) on POSIX.

Reproduction

  1. Pass a PureWindowsPath string (or pathlib.Path) to serialize_vt_snapshot(..., scrubbers=...):

    $ uv run --no-sync python -c '
    import pathlib
    from libvt import Terminal
    from libvt.testing import serialize_vt_snapshot
    
    term = Terminal(rows=1, cols=40)
    term.feed(b"dir=C:\\Users\\runner\\Temp\\run1")
    win_tmp = pathlib.PureWindowsPath("C:/Users/runner/Temp/run1")
    print(serialize_vt_snapshot(term, scrubbers=[(str(win_tmp), "<TMP>")]))
    '

Expected

ScrubberSpec accepts os.PathLike[str] values ((tmp_path, "<TMP>")) and escapes literal path metacharacters and separators cleanly across POSIX and Windows without raising re.PatternError.

Actual

re.compile() treats \U in the Windows path string as an incomplete Unicode escape and raises re.PatternError (while passing win_tmp directly fails type-checking and raises TypeError in _compile_scrubbers()):

re.PatternError: incomplete escape \U at position 2

Environment

Versions
  • libvt: 0.0.1a5 (587227c)
  • Python: 3.15.1
  • OS: Linux (x86_64)

References

Activity

  1. added
    bug
    p2
    on Dec 2, 2026
  2. tony commented on Dec 3, 2026

    @tony
    MemberAuthor

    PR #150 now targets #149’s row-preserving renderer. A literal file path preserved a wrapped URI across both rows of a 10×2 screen, with the cursor at (1, 8). An explicit URI regex replaced it. Cropping the prefix out of view preserved the same literal-match behavior. PR #150 · PR #149

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugp2

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions