Skip to content

Commit

Permalink
Escapes special HTML characters
Browse files Browse the repository at this point in the history
fix errors caused by empty coordinatesList
  • Loading branch information
surfaceocean committed Apr 28, 2024
1 parent 05e6ae2 commit 36dd940
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ def draw(locationsRawList: list, output_path: str, file_name: str) -> None:
+ i[3] + ' ' \
+ 'RTT:' + i[8] + 'ms' # + i[6]
if k == len(locationsRawList) - 1:
textList.append(text)
textList.append(text.replace("&", "&")
.replace("<", "&lt;")
.replace(">", "&gt;")
.replace('"', "&quot;")
.replace("'", "&#039;"))
text = '<br>'.join(textList)
lat += random.uniform(-0.01, 0.01)
lng += random.uniform(-0.01, 0.01)
Expand All @@ -50,10 +54,18 @@ def draw(locationsRawList: list, output_path: str, file_name: str) -> None:
textList = []
break
if lat == locationsRawList[k + 1][0] and lng == locationsRawList[k + 1][1]:
textList.append(text)
textList.append(text.replace("&", "&amp;")
.replace("<", "&lt;")
.replace(">", "&gt;")
.replace('"', "&quot;")
.replace("'", "&#039;"))
continue
else:
textList.append(text)
textList.append(text.replace("&", "&amp;")
.replace("<", "&lt;")
.replace(">", "&gt;")
.replace('"', "&quot;")
.replace("'", "&#039;"))
text = '<br>'.join(textList)
lat += random.uniform(-0.01, 0.01)
lng += random.uniform(-0.01, 0.01)
Expand All @@ -64,7 +76,7 @@ def draw(locationsRawList: list, output_path: str, file_name: str) -> None:
with open('template/template.html', 'r', encoding='utf-8') as f:
template = f.read()
new_content = (template.replace("%_REPLACE_CONTENT0_%", ''.join(content))).replace(
"%_REPLACE_CONTENT1_%",json.dumps(tableDataList,ensure_ascii=False)
"%_REPLACE_CONTENT1_%", json.dumps(tableDataList, ensure_ascii=False)
)
with open(os.path.join(output_path, file_name), 'w', encoding='utf-8') as fp:
fp.write(new_content)
Expand Down Expand Up @@ -109,6 +121,8 @@ def process(rawData: dict, filename=str(int(datetime.datetime.now().timestamp())
]
)
break
if (len(coordinatesList) == 0):
return "没有需要绘制的数据。"
draw(coordinatesList, './html', filename)
return urlPrefix + filename

Expand Down

0 comments on commit 36dd940

Please sign in to comment.