syl20bnr / spacemacs

A community-driven Emacs distribution - The best editor is neither Emacs nor Vim, it's Emacs *and* Vim!
http://spacemacs.org
GNU General Public License v3.0
23.7k stars 4.9k forks source link

spacemacs/python-execute-file cannot handle filenames with spaces #11091

Closed rileylev closed 5 years ago

rileylev commented 6 years ago

Description :octocat:

spacemacs/python-execute-file does not properly handle filenames with spaces.

Reproduction guide :beetle:

Observed behaviour: :eyes: :broken_heart: The *compilation* buffer says

-*- mode: compilation; default-directory: "~/" -*-
Comint started at Fri Jul 27 19:16:22

python two words.py
python: can't open file 'two': [Errno 2] No such file or directory

Inferior Python exited abnormally with code 2 at Fri Jul 27 19:16:23

Expected behaviour: :heart: :smile: The program should execute and *ipython* should display the results of execution

System Info :computer:

Backtrace :paw_prints:

rileylev commented 6 years ago

We're not sanitizing strings before passing to python in shell:

In the function spacemacs/python-execute-file in .emacs.d/+layers/python/funcs.el in the development branch, the compile-command is defined by

(format "%s %s"
         (spacemacs/pyenv-executable-find python-shell-interpreter)
         (file-name-nondirectory buffer-file-name))

If buffer-file-name has spaces in it ("two words.py"), the format command returns "/usr/bin/python two words.py", which will of course run python on two.

rileylev commented 6 years ago

I believe calling shell-quote-argument on the filename before passing to the format command fixes the problem:

(format "python %s" (shell-quote-argument (convert-standard-filename "two words.py")))

returns "python two\\ words.py"

smile13241324 commented 6 years ago

Just noticed that this has been fixed on develop @bmag