Repository: spyder-ide/spyder

Issue:
Infinite loop when "gl-N" (with a single digit) appears in multiline docstring
<!--- **PLEASE READ:** When submitting here, please ensure you've completed the following checklist and checked the boxes to confirm. Issue reports without it may be closed. Thanks! --->

### Issue Report Checklist

* [x] Searched the [issues page](https://github.com/spyder-ide/spyder/issues?q=is%3Aissue) for similar reports
* [x] Read the relevant sections of the [Spyder Troubleshooting Guide](https://github.com/spyder-ide/spyder/wiki/Troubleshooting-Guide-and-FAQ) and followed its advice
* [x] Reproduced the issue after updating with ``conda update spyder`` (or ``pip``, if not using Anaconda)
* [x] Tried basic troubleshooting (if a bug/error)
    * [x] Restarted Spyder
    * [x] Reset preferences with ``spyder --reset``
    * [ ] Reinstalled the latest version of [Anaconda](https://www.anaconda.com/download/)
    * [ ] Tried the other applicable steps from the Troubleshooting Guide
* [ ] Completed the **Problem Description**, **Steps to Reproduce** and **Version** sections below


## Problem Description

When typing a reference to an issue in a multiline docstring,
right after typing for example `gl-1` Spyder freezes, displaying only `gl-` and using 100% CPU.
Happens also with `gh-N` and `bb-N`.

The cursor stops blinking, the whole GUI stops responding, and a forced quit is necessary.

### What steps reproduce the problem?

1. Create blank file
2. Type in
```
"""
gl-1
```
3. Spyder hangs and uses 100% CPU.

### What is the expected output? What do you see instead?

We would expect to have an underlined piece of docstring with a Ctrl-clickable link, as when referencing a GitHub/GitLab/BitBucket issue in a simple string or in a comment.

### Paste Traceback/Error Below (if applicable)
No traceback is available as the GUI completely stops responding.

## 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: 4.0.1
* Python 3.7.6 64-bit 
* Qt 5.12.5 
* PyQt5 5.12.3 
* Linux 5.3.0-26-generic 

### Dependencies
<!--- Please go to the menu entry Help > Dependencies,
press the Copy to clipboard button and paste below --->

```
atomicwrites >=1.2.0         :  1.3.0 (OK)
chardet >=2.0.0              :  3.0.4 (OK)
cloudpickle >=0.5.0          :  1.2.2 (OK)
diff_match_patch >=20181111  :  20181111 (OK)
intervaltree                 :  None (OK)
IPython >=4.0                :  7.11.1 (OK)
jedi =0.14.1                 :  0.14.1 (OK)
keyring                      :  None (OK)
nbconvert >=4.0              :  5.6.1 (OK)
numpydoc >=0.6.0             :  0.9.2 (OK)
pexpect >=4.4.0              :  4.7.0 (OK)
pickleshare >=0.4            :  0.7.5 (OK)
psutil >=0.3                 :  5.6.7 (OK)
pygments >=2.0               :  2.5.2 (OK)
pylint >=0.25                :  2.4.4 (OK)
pyls >=0.31.2;<0.32.0        :  0.31.5 (OK)
xdg >=0.26                   :  0.26 (OK)
zmq >=17                     :  18.1.1 (OK)
qdarkstyle >=2.7             :  2.7 (OK)
qtawesome >=0.5.7            :  0.6.1 (OK)
qtconsole >=4.6.0            :  4.6.0 (OK)
qtpy >=1.5.0                 :  1.9.0 (OK)
rtree >=0.8.3                :  0.9.3 (OK)
sphinx >=0.6.6               :  2.3.1 (OK)
spyder_kernels >=1.8.1;<2.0.0:  1.8.1 (OK)
watchdog                     :  None (OK)
cython >=0.21                :  None (NOK)
matplotlib >=2.0.0           :  3.1.2 (OK)
numpy >=1.7                  :  1.17.3 (OK)
pandas >=0.13.1              :  None (NOK)
scipy >=0.17.0               :  1.3.3 (OK)
sympy >=0.7.3                :  1.5.1 (OK)
```



Discussion:
I can reproduce, working on a fix!

Resolving patch:
diff --git a/spyder/utils/syntaxhighlighters.py b/spyder/utils/syntaxhighlighters.py
--- a/spyder/utils/syntaxhighlighters.py
+++ b/spyder/utils/syntaxhighlighters.py
@@ -311,7 +311,8 @@ def highlight_patterns(self, text, offset=0):
                     font = self.format(start)
                     font.setUnderlineStyle(True)
                     self.setFormat(start, end - start, font)
-            match = self.patterns.search(text, end)
+
+            match = self.patterns.search(text, match.end())
 
     def highlight_spaces(self, text, offset=0):
         """


Test patch:
diff --git a/spyder/plugins/editor/widgets/tests/test_goto.py b/spyder/plugins/editor/widgets/tests/test_goto.py
--- a/spyder/plugins/editor/widgets/tests/test_goto.py
+++ b/spyder/plugins/editor/widgets/tests/test_goto.py
@@ -140,3 +140,17 @@ def interact():
     code_editor.filename = None
     code_editor._last_hover_pattern_key = None
     code_editor._last_hover_pattern_text = None
+
+
+def test_pattern_highlight_regression(qtbot, editorbot):
+    """Fix regression on spyder-ide/spyder#11376. """
+    _, code_editor = editorbot
+    code_editor.show()
+
+    # This was generating an infinite loop
+    code_editor.set_text("'''\ngl-")
+    qtbot.wait(500)
+    code_editor.moveCursor(QTextCursor.End)
+    qtbot.wait(500)
+    qtbot.keyClick(code_editor, Qt.Key_1)
+    qtbot.wait(1000)