Skip to content

Commit

Permalink
Merge pull request #27217 from Expensify/techievivek_fix_form
Browse files Browse the repository at this point in the history
[CP Stag] Return early if the value is empty or non-string

(cherry picked from commit 467f396)
  • Loading branch information
techievivek authored and OSBotify committed Sep 12, 2023
1 parent 6403b63 commit 8e383cd
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/components/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 8e383cd

Please sign in to comment.