]> git.eshelyaron.com Git - emacs.git/commitdiff
Avoid infloop in python
authorDaniel Colascione <dancol@dancol.org>
Tue, 8 Nov 2016 23:26:43 +0000 (15:26 -0800)
committerDaniel Colascione <dancol@dancol.org>
Tue, 8 Nov 2016 23:28:49 +0000 (15:28 -0800)
Fix bug#24905

* lisp/progmodes/python.el (python-info-docstring-p): Improve
infloop avoidance: replace (bobp) with generic test for
forward progress.
* test/lisp/progmodes/python-tests.el (python-bob-infloop-avoid): Add
test for bug#24905

lisp/progmodes/python.el
test/automated/python-tests.el

index 9091289b62eebf0ff3d14817a237765b1efbaeeb..d0d4a7f766ef06e3c65e38ecfac646c931d0091d 100644 (file)
@@ -4865,12 +4865,19 @@ point's current `syntax-ppss'."
              ;; Allow up to two consecutive docstrings only.
              (>=
               2
-              (progn
+              (let (last-backward-sexp-point)
                 (while (save-excursion
                          (python-nav-backward-sexp)
                          (setq backward-sexp-point (point))
                          (and (= indentation (current-indentation))
-                              (not (bobp)) ; Prevent infloop.
+                              ;; Make sure we're always moving point.
+                              ;; If we get stuck in the same position
+                              ;; on consecutive loop iterations,
+                              ;; bail out.
+                              (prog1 (not (eql last-backward-sexp-point
+                                               backward-sexp-point))
+                                (setq last-backward-sexp-point
+                                      backward-sexp-point))
                               (looking-at-p
                                (concat "[uU]?[rR]?"
                                        (python-rx string-delimiter)))))
index 54ed92212b87045a8b0df87da928fca6ae04782d..f6564dd58cc6d9af23ced2c1b7b2dad3f7b1e7ad 100644 (file)
@@ -2452,6 +2452,13 @@ if x:
                 (line-beginning-position) (line-end-position))
                "abcdef")))))
 
+(ert-deftest python-bob-infloop-avoid ()
+  "Test that strings at BOB don't confuse syntax analysis.  Bug#24905"
+  (python-tests-with-temp-buffer
+      " \"\n"
+    (goto-char (point-min))
+    (font-lock-fontify-buffer)))
+
 \f
 ;;; Shell integration