Repository: spyder-ide/spyder

Issue:
Double Quotes at the beginning or end of the a code cell breaks runcell
## Problem Description

runcell sends the code to the kernel formatted as a `"""` string. So `""""` through an error

## To Reproduce

1. put `"Hello World"` in a code cell 
2. run the code cell

### Paste Traceback/Error Below (if applicable)
<!--- Copy from error dialog or View > Panes > Internal Console --->

```python-traceback

runcell('','/home/bcolsen/Documents/projects/bcp/cong_ebeam/untitled1.py')
  File "<ipython-input-138-196bcb471293>", line 28
    "hello""""
              
^
SyntaxError: EOL while scanning string literal

--Run Cell Error--
Please use only through Spyder's Editor; shouldn't be called manually from the console
```

## Versions
<!--- You can get this information from Help > About Spyder...
or (if Spyder won't launch) the "conda list" command
from the Anaconda Prompt/Terminal/command line. --->

* Spyder version: master
* Python version: 3.6
* Qt version: 
* PyQt version: 
* Operating System name/version: 



Discussion:

Resolving patch:
diff --git a/spyder/plugins/editor/widgets/base.py b/spyder/plugins/editor/widgets/base.py
--- a/spyder/plugins/editor/widgets/base.py
+++ b/spyder/plugins/editor/widgets/base.py
@@ -661,33 +661,10 @@ def get_selection_as_executable_code(self):
             else:
                 break
 
-        # Add an EOL character after indentation blocks that start with some
-        # Python reserved words, so that it gets evaluated automatically
-        # by the console
-        varname = re.compile(r'[a-zA-Z0-9_]*')  # Matches valid variable names.
-        maybe = False
-        nextexcept = ()
-        for n, line in enumerate(lines):
-            if not _indent(line):
-                word = varname.match(line).group()
-                if maybe and word not in nextexcept:
-                    lines[n-1] += ls
-                    maybe = False
-                if word:
-                    if word in ('def', 'for', 'while', 'with', 'class'):
-                        maybe = True
-                        nextexcept = ()
-                    elif word == 'if':
-                        maybe = True
-                        nextexcept = ('elif', 'else')
-                    elif word == 'try':
-                        maybe = True
-                        nextexcept = ('except', 'finally')
-        if maybe:
-            if lines[-1].strip() == '':
-                lines[-1] += ls
-            else:
-                lines.append(ls)
+        # Add an EOL character after the last line of code so that it gets
+        # evaluated automatically by the console and any quote characters
+        # are separated from the triple quotes of runcell
+        lines.append(ls)
 
         # Add removed lines back to have correct traceback line numbers
         leading_lines_str = ls * lines_removed
@@ -705,7 +682,6 @@ def __exec_cell(self):
         self.last_cursor_cell = init_cursor
         self.__restore_selection(start_pos, end_pos)
         if text is not None:
-            text = text.rstrip()
             text = ls * line_from + text
         return text, line_from
 
diff --git a/spyder/plugins/editor/widgets/editor.py b/spyder/plugins/editor/widgets/editor.py
--- a/spyder/plugins/editor/widgets/editor.py
+++ b/spyder/plugins/editor/widgets/editor.py
@@ -2392,7 +2392,7 @@ def run_selection(self):
         """
         text = self.get_current_editor().get_selection_as_executable_code()
         if text:
-            self.exec_in_extconsole.emit(text, self.focus_to_editor)
+            self.exec_in_extconsole.emit(text.rstrip(), self.focus_to_editor)
             return
         editor = self.get_current_editor()
         line = editor.get_current_line()


Test patch:
diff --git a/spyder/app/tests/script.py b/spyder/app/tests/script.py
--- a/spyder/app/tests/script.py
+++ b/spyder/app/tests/script.py
@@ -1,6 +1,6 @@
 # %% first Code Cell's name
 a = 10
-
+"Hello"
 
 # In[23]
 li = [1, 2, 3]
diff --git a/spyder/widgets/tests/test_shortcutssummary.py b/spyder/widgets/tests/test_shortcutssummary.py
--- a/spyder/widgets/tests/test_shortcutssummary.py
+++ b/spyder/widgets/tests/test_shortcutssummary.py
@@ -60,6 +60,6 @@ def test_shortcutssummary_texts(dlg_shortcuts, qtbot):
                 if sys.platform.startswith('darwin'):
                     keywords = [u'⇧', u'⌃', u'⌘', u'⌥', u'⌦',  u'⎋', 'F']
                 else:
-                    keywords = ['Alt', 'Ctrl', 'Del', 'Escape', 'F', 'Meta',
+                    keywords = ['Alt', 'Ctrl', 'Del', 'Esc', 'F', 'Meta',
                                 'Shift']
                 assert any([key in shortcut_keystr for key in keywords])