Fix #13084 by madbird1304 · Pull Request #13093 · ipython/ipython (original) (raw)

Ugh... I didn't wanted list2cmdline cause it's MSC specific but it turns out that shlex.quote also isn't "platform agnostic". It didn't occur to me that single quotes would have different meaning to double quotes - I should've tested it on Windows.

One other argument against using list2cmdline: it isn't really "public" in the same sense other methods of subprocess are. It's an implementation detail, not a "public API".

Furthermore, I feel like introducing MSC shell semantics on all other platforms will introduce subtle bugs and edge cases. A simple .replace("'", "\"") also isn't enough, since virtualenv paths can contain " on UNIX-es.

At this point I'm questioning whether this should even use shell.system. I should probably look into creating a argv-style API for shell commands in magics. But let's fix this first. Any changes to the shell.system API would probably need to go into 8.0, and we need to get the fix into 7.27.

I don't see any other option than using something like if sys.platform == "win32": "\"" + s + "\""; else: shlex.quote(...).