You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description
Using escape to print something with a trailing slash does not escape the trailing slash:
from rich import print; from rich.markup import escape
value = "C:\\"; print(value)
rich.print(f"[red]{value}[/red]") # <-- [ gets escaped
rich.print(f"[red]{escape(value)}[/red]") # <-- [ still gets escaped
outputs
C:\
C:[/red]
C:[/red]
Possible solution
# Previous character is NOT a slash: (?<![\\])
# some number of escaped slashes: (?:[\\][\\])*
# followed by a lone slash at end-of-string: [\\]$
In [40]: _odd_trailing_escape_re = r'(?<![\\])(?:[\\][\\])*[\\]$'
...: def escape(text: str, trailing_slash_check = re.compile(_odd_trailing_escape_re, flags=re.S).search) -> str:
...:
...: if text.endswith('\\') and trailing_slash_check(text):
...: text += '\\'
...: return text
...:
In [41]: escape("C:\\")
Out[41]: 'C:\\\\'
In [42]: escape("C:\\\\")
Out[42]: 'C:\\\\'
In [43]: escape("C:\\\\\\")
Out[43]: 'C:\\\\\\\\'```
**Platform**
Using Rich in a terminal:
Description
Using escape to print something with a trailing slash does not escape the trailing slash:
outputs
Possible solution
Win|PS> python -m rich.diagnose ; pip freeze | sls rich
╭───────────────────────── <class 'rich.console.Console'> ─────────────────────────╮
│ A high level console interface. │
│ │
│ ╭──────────────────────────────────────────────────────────────────────────────╮ │
│ │ │ │
│ ╰──────────────────────────────────────────────────────────────────────────────╯ │
│ │
│ color_system = 'truecolor' │
│ encoding = 'utf-8' │
│ file = <_io.TextIOWrapper name='' mode='w' encoding='utf-8'> │
│ height = 30 │
│ is_alt_screen = False │
│ is_dumb_terminal = False │
│ is_interactive = True │
│ is_jupyter = False │
│ is_terminal = True │
│ legacy_windows = False │
│ no_color = False │
│ options = ConsoleOptions( │
│ size=ConsoleDimensions(width=118, height=30), │
│ legacy_windows=False, │
│ min_width=1, │
│ max_width=118, │
│ is_terminal=True, │
│ encoding='utf-8', │
│ max_height=30, │
│ justify=None, │
│ overflow=None, │
│ no_wrap=False, │
│ highlight=None, │
│ markup=None, │
│ height=None │
│ ) │
│ quiet = False │
│ record = False │
│ safe_box = True │
│ size = ConsoleDimensions(width=118, height=30) │
│ soft_wrap = False │
│ stderr = False │
│ style = None │
│ tab_size = 8 │
│ width = 118 │
╰──────────────────────────────────────────────────────────────────────────────────╯
╭── <class 'rich._windows.WindowsConsoleFeatures'> ───╮
│ Windows features available. │
│ │
│ ╭─────────────────────────────────────────────────╮ │
│ │ WindowsConsoleFeatures(vt=True, truecolor=True) │ │
│ ╰─────────────────────────────────────────────────╯ │
│ │
│ truecolor = True │
│ vt = True │
╰─────────────────────────────────────────────────────╯
╭────── Environment Variables ───────╮
│ { │
│ 'TERM': None, │
│ 'COLORTERM': None, │
│ 'CLICOLOR': None, │
│ 'NO_COLOR': None, │
│ 'TERM_PROGRAM': None, │
│ 'COLUMNS': None, │
│ 'LINES': None, │
│ 'JUPYTER_COLUMNS': None, │
│ 'JUPYTER_LINES': None, │
│ 'JPY_PARENT_PID': None, │
│ 'VSCODE_VERBOSE_LOGGING': None │
│ } │
╰────────────────────────────────────╯
platform="Windows"
rich @ file:///home/conda/feedstock_root/build_artifacts/rich-split_1685565049610/work/dist
The text was updated successfully, but these errors were encountered: