28 lines
855 B
Python
28 lines
855 B
Python
"""Fix chat JS: replace the problematic /s regex flag with safe alternative."""
|
|
path = "/home/ubuntu/ai-chat/app.py"
|
|
|
|
with open(path) as f:
|
|
content = f.read()
|
|
|
|
# Replace the problematic regex with /s flag
|
|
old = """s=s.replace(/(<li>.*<\\/li>)/s,'<ul>$1</ul>');"""
|
|
new = """s=s.replace(/(<li>[^]*?<\\/li>)/g,function(m){return '<ul>'+m+'</ul>';});"""
|
|
|
|
if old in content:
|
|
content = content.replace(old, new)
|
|
print("Fixed /s flag regex")
|
|
else:
|
|
print("Pattern not found, checking alternatives...")
|
|
# Try unescaped version
|
|
old2 = "s=s.replace(/(<li>.*<\\/li>)/s,'<ul>$1</ul>');"
|
|
if old2 in content:
|
|
content = content.replace(old2, new)
|
|
print("Fixed (alt)")
|
|
|
|
with open(path, "w") as f:
|
|
f.write(content)
|
|
|
|
# Verify: count the _md function
|
|
count = content.count("function _md(s)")
|
|
print(f"_md definitions: {count}")
|