Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/client/src/widgets/InputWidgetV2/widget/derived.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export default {
* https://stackoverflow.com/questions/15017052/understanding-email-validation-using-javascript
* */
const emailRegex = new RegExp(
/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/,
/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,6})+$/,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrap the emailRegex declaration in a block to restrict its scope within the switch case.

- const emailRegex = new RegExp(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,6})+$/);
+ {
  const emailRegex = new RegExp(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,6})+$/);
  if (!emailRegex.test(value)) {
    return false;
  } else if (parsedRegex) {
    return parsedRegex.test(props.inputText);
  } else {
    return true;
  }
}
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,6})+$/,
{
const emailRegex = new RegExp(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,6})+$/);
if (!emailRegex.test(value)) {
return false;
} else if (parsedRegex) {
return parsedRegex.test(props.inputText);
} else {
return true;
}
}

);
if (!emailRegex.test(value)) {
/* email should conform to generic email regex */
Expand Down
13 changes: 13 additions & 0 deletions app/client/src/widgets/InputWidgetV2/widget/derived.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,19 @@ describe("Derived property - ", () => {
_,
);

expect(isValid).toBeFalsy();

//Email input with required true and valid value
isValid = derivedProperty.isValid(
{
inputType: InputTypes.EMAIL,
inputText: "[email protected]",
isRequired: true,
},
null,
_,
);

expect(isValid).toBeTruthy();

//Password input with required false and empty value
Expand Down