Skip to content

Commit

Permalink
BUG: Issue ipython#755 qt IPythonWidget.execute_file fails if filenam…
Browse files Browse the repository at this point in the history
…e contains single and double quotes
  • Loading branch information
Jonathan March committed Dec 8, 2011
1 parent ee40ebe commit ebfa946
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions IPython/frontend/qt/console/ipython_widget.py
Expand Up @@ -276,14 +276,16 @@ def execute_file(self, path, hidden=False):
path = os.path.normpath(path).replace('\\', '/')

# Perhaps we should not be using %run directly, but while we
# are, it is necessary to quote filenames containing spaces or quotes.
# Escaping quotes in filename in %run seems tricky and inconsistent,
# so not trying it at present.
# are, it is necessary to quote or escape filenames containing spaces
# or quotes. As much as possible, we quote: more readable than escape.
if '"' in path:
if "'" in path:
raise ValueError("Can't run filename containing both single "
"and double quotes: %s" % path)
path = "'%s'" % path
# In this case, because %run 'a\'b"c.py' fails, we must escape
# all quotes and spaces.
for c in '" \'':
path = path.replace(c, '\\'+c)
else:
path = "'%s'" % path
elif ' ' in path or "'" in path:
path = '"%s"' % path

Expand Down

0 comments on commit ebfa946

Please sign in to comment.