Explorar el Código

html字符转义

xsx hace 11 meses
padre
commit
7a43ba72fe
Se han modificado 1 ficheros con 11 adiciones y 1 borrados
  1. 11 1
      im-uniapp/pages/chat/chat-box.vue

+ 11 - 1
im-uniapp/pages/chat/chat-box.vue

@@ -289,7 +289,7 @@ export default {
 					let receiptText = this.isReceipt ? "【回执消息】" : "";
 					let atText = this.createAtText();
 					let msgInfo = {
-						content: receiptText + sendText + atText,
+						content: receiptText + this.html2Escape(sendText) + atText,
 						atUserIds: this.atUserIds,
 						receipt: this.isReceipt,
 						type: 0
@@ -688,6 +688,16 @@ export default {
 			let px = info.windowWidth * rpx / 750;
 			return Math.floor(rpx);
 		},
+		html2Escape(strHtml) {
+			return strHtml.replace(/[<>&"]/g, function(c) {
+				return {
+					'<': '&lt;',
+					'>': '&gt;',
+					'&': '&amp;',
+					'"': '&quot;'
+				} [c];
+			});
+		},
 		sendMessageRequest(msgInfo) {
 			return new Promise((resolve, reject) => {
 				// 请求入队列,防止请求"后发先至",导致消息错序