From cd0a1597faa83f161e45ed4d5ae988a1f2961b0f Mon Sep 17 00:00:00 2001 From: Lei OT Date: Sun, 7 Apr 2024 14:35:30 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E6=A8=A1=E6=9D=BF=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E8=BE=93=E5=85=A5:=20=E5=88=A0=E9=99=A4=E5=A4=9A=E4=BD=99?= =?UTF-8?q?=E7=9A=84=E7=A9=BA=E6=A0=BC.=20=0Berror=20details:=20Param=20te?= =?UTF-8?q?xt=20cannot=20have=20new-line/tab=20characters=20or=20more=20th?= =?UTF-8?q?an=204=20consecutive=20spaces?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/commons.js | 5 ++++- src/views/Conversations/Online/Input/Template.jsx | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/utils/commons.js b/src/utils/commons.js index 687cdc1..c6d548d 100644 --- a/src/utils/commons.js +++ b/src/utils/commons.js @@ -425,7 +425,10 @@ export const debounce = (func, wait, immediate) => { export const removeFormattingChars = (str) => { const regex = /[\r\n\t\v\f]/g; - return str.replace(regex, ' '); + str = str.replace(regex, ' '); + // Replace more than four consecutive spaces with a single space + str = str.replace(/\s{4,}/g, ' '); + return str; } export const olog = (text, ...args) => { diff --git a/src/views/Conversations/Online/Input/Template.jsx b/src/views/Conversations/Online/Input/Template.jsx index 3670aac..588553e 100644 --- a/src/views/Conversations/Online/Input/Template.jsx +++ b/src/views/Conversations/Online/Input/Template.jsx @@ -97,7 +97,7 @@ const InputTemplate = ({ mobile, disabled = false, invokeSendMessage }) => { const [activeInput, setActiveInput] = useState({}); const onInput = (tempItem, key, val, initObj) => { - const _val = removeFormattingChars(val); + const _val = removeFormattingChars(val); // Param text cannot have new-line/tab characters or more than 4 consecutive spaces setActiveInput((prev) => { return { ...prev, [tempItem.name]: { ...initObj, ...prev[tempItem.name], [key]: _val } }; });