Skip to content

Commit 41d4aa2

Browse files
committed
Fixed unicode bug on Windows in pyscript command
Without using the repr representation of the path, "C:\Users" treats \U as a Unicode Escape. To fix this, pyscript passes the repr representation of the path to do_py.
1 parent a949834 commit 41d4aa2

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

cmd2.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,7 +1421,7 @@ def do_pyscript(self, arg, opts=None):
14211421
arg = shlex.split(arg, posix=POSIX_SHLEX)
14221422

14231423
# Get the absolute path of the script
1424-
script_path = os.path.abspath(os.path.expanduser(arg[0]))
1424+
script_path = os.path.expanduser(arg[0])
14251425

14261426
# Save current command line arguments
14271427
orig_args = sys.argv
@@ -1430,8 +1430,9 @@ def do_pyscript(self, arg, opts=None):
14301430
sys.argv = [script_path]
14311431
sys.argv.extend(arg[1:])
14321432

1433-
# Run the script
1434-
self.do_py("run('{}')".format(script_path))
1433+
# Run the script - use repr formatting to escape things which need to be escaped to prevent issues on Windows
1434+
py_cmd = "run({!r})".format(script_path)
1435+
self.do_py(py_cmd)
14351436

14361437
# Restore command line arguments to original state
14371438
sys.argv = orig_args

0 commit comments

Comments
 (0)