Spaces:
Sleeping
Sleeping
fix: correct regex backreference in infinite recursion detection - enable API functionality
Browse files- fix_regex.py +25 -0
- main.py +2 -2
fix_regex.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Fix bad regex backreferences in main.py"""
|
| 3 |
+
|
| 4 |
+
with open('main.py', 'r', encoding='utf-8') as f:
|
| 5 |
+
content = f.read()
|
| 6 |
+
|
| 7 |
+
# Replace the bad pattern with the fixed one
|
| 8 |
+
# OLD: r'def\s+\w+.*:\s*.*return\s+\1\s*\('
|
| 9 |
+
# NEW: r'def\s+(\w+).*:\s*.*return\s+\1\s*\('
|
| 10 |
+
# The key change: \w+ -> (\w+) to create capturing group 1
|
| 11 |
+
|
| 12 |
+
bad_pattern = r"r'def\s+\w+.*:\s*.*return\s+\1\s*\('"
|
| 13 |
+
good_pattern = r"r'def\s+(\w+).*:\s*.*return\s+\1\s*\('"
|
| 14 |
+
|
| 15 |
+
# Use simple string replacement
|
| 16 |
+
fixed_content = content.replace(bad_pattern, good_pattern)
|
| 17 |
+
|
| 18 |
+
if fixed_content != content:
|
| 19 |
+
with open('main.py', 'w', encoding='utf-8') as f:
|
| 20 |
+
f.write(fixed_content)
|
| 21 |
+
# Count replacements
|
| 22 |
+
count = content.count(bad_pattern)
|
| 23 |
+
print(f"SUCCESS: Fixed {count} regex backreference(s) in main.py")
|
| 24 |
+
else:
|
| 25 |
+
print("No changes needed - pattern not found or already fixed")
|
main.py
CHANGED
|
@@ -248,7 +248,7 @@ def analyze_code_comprehensively(code: str, lang: str) -> list:
|
|
| 248 |
})
|
| 249 |
|
| 250 |
# Infinite recursion (Python)
|
| 251 |
-
if lang == 'python' and re.search(r'def\s+\w+.*:\s*.*return\s+\1\s*\(', code, re.DOTALL):
|
| 252 |
bugs.append({
|
| 253 |
"type": "bug", "category": "logic", "severity": 3, "line_hint": 2,
|
| 254 |
"comment": "Infinite recursion: Function calls itself without base case.",
|
|
@@ -490,7 +490,7 @@ async def get_stats():
|
|
| 490 |
})
|
| 491 |
|
| 492 |
# Infinite recursion (Python)
|
| 493 |
-
if lang == 'python' and re.search(r'def\s+\w+.*:\s*.*return\s+\1\s*\(', code, re.DOTALL):
|
| 494 |
bugs.append({
|
| 495 |
"type": "bug", "category": "logic", "severity": 3, "line_hint": 2,
|
| 496 |
"comment": "Infinite recursion: Function calls itself without base case.",
|
|
|
|
| 248 |
})
|
| 249 |
|
| 250 |
# Infinite recursion (Python)
|
| 251 |
+
if lang == 'python' and re.search(r'def\s+(\w+).*:\s*.*return\s+\1\s*\(', code, re.DOTALL):
|
| 252 |
bugs.append({
|
| 253 |
"type": "bug", "category": "logic", "severity": 3, "line_hint": 2,
|
| 254 |
"comment": "Infinite recursion: Function calls itself without base case.",
|
|
|
|
| 490 |
})
|
| 491 |
|
| 492 |
# Infinite recursion (Python)
|
| 493 |
+
if lang == 'python' and re.search(r'def\s+(\w+).*:\s*.*return\s+\1\s*\(', code, re.DOTALL):
|
| 494 |
bugs.append({
|
| 495 |
"type": "bug", "category": "logic", "severity": 3, "line_hint": 2,
|
| 496 |
"comment": "Infinite recursion: Function calls itself without base case.",
|