Skip to content

Commit ed2b91a

Browse files
committed
fix(repl): preserve backslashes in dot-command argument paths
`.save C:\Users\…\scratch.robot` mangled the path on Windows because `shlex.split` consumes backslashes as escape characters. Switch to a custom shlex with `escape=""` so paths arrive intact while shell-style quoting (for spaces in paths) still works.
1 parent 02d8177 commit ed2b91a

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

packages/repl/src/robotcode/repl/_dot_commands.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,17 @@ def _exit(app: Application, interpreter: Any, arg: str) -> None:
490490
# ---------------------------------------------------------------------------
491491

492492

493+
def _split_command_args(arg: str) -> List[str]:
494+
"""Tokenise a dot-command argument string the way shells do — but
495+
keep backslashes literal so Windows paths (``C:\\Users\\…``) survive
496+
unmangled. Quotes still work for spaces in paths."""
497+
lex = shlex.shlex(arg, posix=True)
498+
lex.whitespace_split = True
499+
lex.escape = ""
500+
lex.commenters = ""
501+
return list(lex)
502+
503+
493504
def _build_save_parser() -> argparse.ArgumentParser:
494505
# `exit_on_error=False` so a bad invocation reports "Usage: …" via
495506
# `_save` instead of tearing down the REPL on argparse's sys.exit.
@@ -532,7 +543,7 @@ def _save(app: Application, interpreter: Any, arg: str) -> None:
532543
"""
533544
parser = _build_save_parser()
534545
try:
535-
opts = parser.parse_args(shlex.split(arg))
546+
opts = parser.parse_args(_split_command_args(arg))
536547
except (argparse.ArgumentError, SystemExit, ValueError):
537548
app.echo("Usage: .save [-a] [-t NAME] FILENAME")
538549
return

0 commit comments

Comments
 (0)