avoid infinite loop in search
authorAndrey Skvortsov <andrej.skvortzov@gmail.com>
Fri, 09 Jun 2017 18:12:12 +0300
changeset 1695 a63bb4025852
parent 1694 acb767d6ac85
child 1696 8043f32de7b8
avoid infinite loop in search

for example following regexp '()' creates infinite list of result
plcopen/plcopen.py
--- a/plcopen/plcopen.py	Thu Jun 08 17:30:23 2017 +0300
+++ b/plcopen/plcopen.py	Fri Jun 09 18:12:12 2017 +0300
@@ -125,10 +125,13 @@
     test_result = []
     result = criteria["pattern"].search(text)
     while result is not None:
+        prev_pos=result.endpos        
         start = TextLenInRowColumn(text[:result.start()])
         end = TextLenInRowColumn(text[:result.end() - 1])
         test_result.append((start, end, "\n".join(lines[start[0]:end[0] + 1])))
         result = criteria["pattern"].search(text, result.end())
+        if result is not None and prev_pos==result.endpos:
+            break
     return test_result
 
 def TextMatched(str1, str2):