From 745425458beda1905597f9299b231a2ac001d18c Mon Sep 17 00:00:00 2001
From: Ubuntu
Date: Sun, 14 Jun 2026 15:32:31 +0800
Subject: [PATCH] fix: remove /s flag in markdown regex, add conversation
delete
---
app.py | 2 +-
chat.db | Bin 61440 -> 61440 bytes
fix_chat_js.py | 29 +++++++++++++++++++++++++++++
fix_chat_v2.py | 27 +++++++++++++++++++++++++++
4 files changed, 57 insertions(+), 1 deletion(-)
create mode 100644 fix_chat_js.py
create mode 100644 fix_chat_v2.py
diff --git a/app.py b/app.py
index 4965349..c5770b2 100644
--- a/app.py
+++ b/app.py
@@ -269,7 +269,7 @@ function _md(s){
s=s.replace(/\*(.+?)\*/g,'$1');
// Lists
s=s.replace(/^\s*[-*]\s+(.+)$/gm,'$1');
- s=s.replace(/(.*<\/li>)/s,'');
+ s=s.replace(/([^]*?<\/li>)/g,function(m){return '';});
// Line breaks (double newline = paragraph)
s=s.replace(/\n\n/g,'
');
s=s.replace(/\n/g,'
');
diff --git a/chat.db b/chat.db
index 20999600d5f41a690803bf31935faafa09266bb0..59f61d4f64ea8963890a5c2094cb377e0cb549c5 100644
GIT binary patch
delta 405
zcmZp8z})bFd4e>f-9#B@M!Ss(OZb@uxmhQ(3n(&ivu
&1G&X$SNynY@C>4l9-xg
zW|om@WME{bYhb2pXrf?fY-MafHV&$Ff#&u6tf>uGEB_AS)^ecW`NOY7y3e++6T@0uKOLhoDjb
delta 113
zcmV-%0FM8F-~)i*1CSd5Jdqqj0X(r_qz?lS3p|qt5FxRF6brLF8^{DC5Dzf`519|M
z4?Yh|584l=4~!334{{H{4>1q)59beM4}TBMvmr1E53?~Z&L9CgvQPw&4g~{n01Flh
Tp$32kAp>x+fnEc%aO02+Pbwh|
diff --git a/fix_chat_js.py b/fix_chat_js.py
new file mode 100644
index 0000000..1be8307
--- /dev/null
+++ b/fix_chat_js.py
@@ -0,0 +1,29 @@
+"""Fix chat JS: remove duplicate _a() function, cleanup."""
+path = "/home/ubuntu/ai-chat/app.py"
+with open(path) as f:
+ content = f.read()
+
+# Remove the second (old) _a function that's overwriting the markdown one
+# It appears right after _md() returns
+old_dup = """ return ''+s+'
';
+}
+function _a(r,t){var d=document.createElement("div");d.className="msg "+r;
+ var b=document.createElement("div");b.className="bb";b.textContent=t;
+ d.appendChild(b);document.getElementById("cht").appendChild(d);
+ document.getElementById("cht").scrollTop=document.getElementById("cht").scrollHeight;}"""
+
+new_clean = """ return ''+s+'
';
+}"""
+
+content = content.replace(old_dup, new_clean)
+
+with open(path, "w") as f:
+ f.write(content)
+
+# Verify syntax: count _a definitions
+count = content.count("function _a(r,t){")
+print(f"Chat app fixed. _a definitions: {count} (should be 1)")
+if count != 1:
+ print("WARNING: Still have duplicate _a functions!")
+else:
+ print("OK - single _a function with markdown support")
diff --git a/fix_chat_v2.py b/fix_chat_v2.py
new file mode 100644
index 0000000..fbd71e7
--- /dev/null
+++ b/fix_chat_v2.py
@@ -0,0 +1,27 @@
+"""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>)/s,'');"""
+new = """s=s.replace(/([^]*?<\\/li>)/g,function(m){return '';});"""
+
+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>)/s,'');"
+ 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}")