Skip to content

Commit

Permalink
修复str_content转义问题
Browse files Browse the repository at this point in the history
  • Loading branch information
LC044 committed Nov 28, 2023
1 parent 5f11483 commit 641c880
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions app/DataBase/output_pc.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import csv
import html
import os

from PyQt5.QtCore import pyqtSignal, QThread
Expand All @@ -10,6 +11,24 @@
os.mkdir('./data/聊天记录')


def escape_js_and_html(input_str):
# 转义HTML特殊字符
html_escaped = html.escape(input_str, quote=False)

# 手动处理JavaScript转义字符
js_escaped = (
html_escaped
.replace("\\", "\\\\")
.replace("'", r"\'")
.replace('"', r'\"')
.replace("\n", r'\n')
.replace("\r", r'\r')
.replace("\t", r'\t')
)

return js_escaped


class Output(QThread):
"""
发送信息线程
Expand Down Expand Up @@ -638,9 +657,7 @@ def to_html_(self):
avatar = 'myhead.png' if is_send else 'tahead.png'
timestamp = message[5]
self.progressSignal.emit(index)
str_content = str_content.replace('"', '\\"').replace('{', '\\{').replace('}', '\\}').replace('\n',
'\\n').replace(
"'", "\\'")
str_content = escape_js_and_html(str_content)
if type_ == 1:
if self.is_5_min(timestamp):
f.write(
Expand Down

0 comments on commit 641c880

Please sign in to comment.