diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2017-07-01 20:02:17 -0400 |
---|---|---|
committer | Todd Leonhardt <todd.leonhardt@gmail.com> | 2017-07-01 20:02:17 -0400 |
commit | 41d4aa2e7d9957dd13786e93a1af42949c82fa25 (patch) | |
tree | 8cc200383d5f4633511e608f1ea8232e7441f750 | |
parent | a949834c4c55b4fdbec32cba09e5fe5f5bdc15fa (diff) | |
download | cmd2-git-41d4aa2e7d9957dd13786e93a1af42949c82fa25.tar.gz |
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.
-rwxr-xr-x | cmd2.py | 7 |
1 files changed, 4 insertions, 3 deletions
@@ -1421,7 +1421,7 @@ Paths or arguments that contain spaces must be enclosed in quotes arg = shlex.split(arg, posix=POSIX_SHLEX) # Get the absolute path of the script - script_path = os.path.abspath(os.path.expanduser(arg[0])) + script_path = os.path.expanduser(arg[0]) # Save current command line arguments orig_args = sys.argv @@ -1430,8 +1430,9 @@ Paths or arguments that contain spaces must be enclosed in quotes sys.argv = [script_path] sys.argv.extend(arg[1:]) - # Run the script - self.do_py("run('{}')".format(script_path)) + # Run the script - use repr formatting to escape things which need to be escaped to prevent issues on Windows + py_cmd = "run({!r})".format(script_path) + self.do_py(py_cmd) # Restore command line arguments to original state sys.argv = orig_args |