branch: externals/sql-indent
commit 96ba814c59b975c434c0ac278f3f53bef93f8d51
Author: Alex Harsanyi <[email protected]>
Commit: Alex Harsanyi <[email protected]>

    Avoid infinite loop in `sqlind-syntax-in-case`
    
    Updated the test case with code that triggered the bug
---
 sql-indent.el               |  5 +++--
 test-data/case-stmt-syn.eld | 13 +++++++++++++
 test-data/case-stmt.sql     |  7 +++++++
 3 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/sql-indent.el b/sql-indent.el
index c34e081..1bd28f3 100644
--- a/sql-indent.el
+++ b/sql-indent.el
@@ -762,8 +762,9 @@ reverse order (a stack) and is used to skip over nested 
blocks."
            (cons 'case-clause-item (point)))
           (t
            ;; It is a statement continuation from the closest CASE element
-           (while (not (and (re-search-backward sqlind-case-clauses-regexp 
start 'noerror)
-                            (sqlind-same-level-statement (point) start)))
+           (while (and (not (= (point) start))
+                       (not (and (re-search-backward 
sqlind-case-clauses-regexp start 'noerror)
+                                 (sqlind-same-level-statement (point) start))))
              nil)
            (cons 'case-clause-item-cont (point))))))
 
diff --git a/test-data/case-stmt-syn.eld b/test-data/case-stmt-syn.eld
index f9b4e25..8754144 100644
--- a/test-data/case-stmt-syn.eld
+++ b/test-data/case-stmt-syn.eld
@@ -18,5 +18,18 @@
   (statement-continuation . 52))
  ((select-clause . 52)
   (statement-continuation . 52))
+ ((toplevel . 1))
+ ((toplevel . 1))
+ ((case-clause-item-cont . 197)
+  (statement-continuation . 190))
+ ((case-clause . 197)
+  (statement-continuation . 190))
+ ((case-clause . 197)
+  (statement-continuation . 190))
+ ((case-clause . 197)
+  (statement-continuation . 190))
+ (((block-end case "")
+   . 197)
+  (statement-continuation . 190))
  ((toplevel . 1)))
  
diff --git a/test-data/case-stmt.sql b/test-data/case-stmt.sql
index 8a6e32e..7c9193b 100644
--- a/test-data/case-stmt.sql
+++ b/test-data/case-stmt.sql
@@ -6,3 +6,10 @@ SELECT y ,
        ELSE "poor"
        END AS level
   FROM bar;
+
+var := CASE
+        var                             -- tricky case
+       WHEN foo>5 THEN "great"
+       WHEN foo=5 THEN "normal"
+       ELSE "poor"
+       END;

Reply via email to