From 8e383cdfa231021ce906ca868e0041a71d843e77 Mon Sep 17 00:00:00 2001 From: Vivek Kumar <35863227+techievivek@users.noreply.github.com> Date: Tue, 12 Sep 2023 21:42:39 +0530 Subject: [PATCH] Merge pull request #27217 from Expensify/techievivek_fix_form [CP Stag] Return early if the value is empty or non-string (cherry picked from commit 467f396625af24ffda0649371b25d57ad762f1b9) --- src/components/Form.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/components/Form.js b/src/components/Form.js index 95c53b29e18d..ef6c3ea10474 100644 --- a/src/components/Form.js +++ b/src/components/Form.js @@ -140,11 +140,15 @@ function Form(props) { // Validate the input for html tags. It should supercede any other error _.each(trimmedStringValues, (inputValue, inputID) => { + // If the input value is empty OR is non-string, we don't need to validate it for HTML tags + if (!inputValue || !_.isString(inputValue)) { + return; + } const foundHtmlTagIndex = inputValue.search(CONST.VALIDATE_FOR_HTML_TAG_REGEX); const leadingSpaceIndex = inputValue.search(CONST.VALIDATE_FOR_LEADINGSPACES_HTML_TAG_REGEX); - // Return early if there is no value OR the value is not a string OR there are no HTML characters - if (!inputValue || !_.isString(inputValue) || (leadingSpaceIndex === -1 && foundHtmlTagIndex === -1)) { + // Return early if there are no HTML characters + if (leadingSpaceIndex === -1 && foundHtmlTagIndex === -1) { return; }