Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: Fix a bug when running a file with a single quote character in its name #6772

Merged
merged 5 commits into from
May 26, 2018

Conversation

jnsebgosselin
Copy link
Member

@jnsebgosselin jnsebgosselin commented Mar 16, 2018

Fixes #6771
Blocking PR #6750
Related to Issue #2158

In spyder/plugins/editor.py, single and double quotes are escaped before running a file from the editor :

https://github.com/spyder-ide/spyder/blob/v3.2.8/spyder/plugins/editor.py#L2380

# Escape single and double quotes in fname (Fixes Issue 2158)
fname = fname.replace("'", r"\'")
fname = fname.replace('"', r'\"')

In Windows, this causes osp.dirname(fname) to return the wrong path if there is a ' or " character in the name of the file. For example :

import os.path as osp
fname="C:\test'path.py"
fname = fname.replace("'", r"\'")
osp.dirname(fname)

returns in Windows 'C:\test' instead of 'C:. Therefore, to fix this issue, fname's dirname must be saved in a temporary variable before the single or double quote are escaped.

Note:
In Windows, the following characters are not allowed for folder or file names :
image

@jnsebgosselin jnsebgosselin added this to the v3.2.9 milestone Mar 16, 2018
@jnsebgosselin jnsebgosselin self-assigned this Mar 16, 2018
@jnsebgosselin
Copy link
Member Author

The test that covers this (test_run_code) is skipped for Windows... so that won't be very useful. But I've tested it locally and the test fails without the changes made in this PR, but pass with the changes.

Copy link
Member

@CAM-Gerlach CAM-Gerlach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few minor notes.

@@ -763,19 +773,20 @@ def test_set_new_breakpoints(main_window, qtbot):
main_window.editor.clear_all_breakpoints()
main_window.editor.close_file()


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this line removed? Two spaces between top-level functions, I thought...accident?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, ty

@@ -1465,4 +1476,4 @@ def test_render_issue():


if __name__ == "__main__":
pytest.main()
pytest.main(['-x', os.path.basename(__file__), '-v', '-rw'])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there is a reason this was changed, particularly adding the -x option? In general, when running locally I usually use -v (or -vv) and always use -rw, but almost never want -x and would have to routinely modify the runtests.py file to change this if I wanted to run the whole test suite with this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running the whole suite when trying to make a single test work is not very efficient. I forgot to exclude this change when committing, I'll simply revert in another commit.

dirname = osp.dirname(fname)

# Escape single and double quotes in fname and dirname
# (Fixes Issue 2158)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add # sign for consistency with previous comment ( #2158 )

@@ -135,6 +135,16 @@ def find_desired_tab_in_window(tab_name, window):
return None, None


def setup_file_test():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the tmpdir fixture for the location of this file.

@@ -770,12 +780,14 @@ def test_set_new_breakpoints(main_window, qtbot):
def test_run_code(main_window, qtbot):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the skipif condition for Windows here.

@pep8speaks
Copy link

Hello @jnsebgosselin! Thanks for updating the PR.

Line 772:80: E501 line too long (96 > 79 characters)

@ccordoba12
Copy link
Member

The failure in CircleCI is unrelated to this.

@ccordoba12 ccordoba12 changed the title PR: Fix a bug when running a file in the IPython console with a single quote character in its name PR: Fix a bug when running a file with a single quote character in its name May 26, 2018
@ccordoba12 ccordoba12 merged commit 9188b9c into spyder-ide:3.x May 26, 2018
ccordoba12 added a commit that referenced this pull request May 26, 2018
@jnsebgosselin
Copy link
Member Author

Thanks @ccordoba12 !

@jnsebgosselin jnsebgosselin deleted the run_pythonfile_with_coma branch August 19, 2018 22:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants