Skip to content

Commit

Permalink
[ES-1665] regex validation fixes. (#1074)
Browse files Browse the repository at this point in the history
Signed-off-by: GurukiranP <[email protected]>
  • Loading branch information
gk-4VII authored Dec 23, 2024
1 parent 653c967 commit f2f3bbf
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 41 deletions.
2 changes: 1 addition & 1 deletion oidc-ui/src/components/InputWithImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ export default function InputWithImage({
onBlur={onBlurChange}
onKeyDown={handleKeyDown}
onKeyUp={handleKeyUp}
value={value}
// value={value}
type={type}
id={id}
name={name}
Expand Down
13 changes: 5 additions & 8 deletions oidc-ui/src/components/InputWithPrefix.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,23 +76,20 @@ const InputWithPrefix = (props) => {
const regex = idProperties.regex ? new RegExp(idProperties.regex) : null;
const trimmedValue = e.target.value.trim();

let newValue = regex
let newValue = regex && regex.test(trimmedValue)
? trimmedValue
.split("")
.filter((char) => regex.test(char))
.join("")
: trimmedValue;

setIndividualId(newValue);
props.individualId(newValue); // Update state with the visible valid value

const isValidInput =
(!maxLength && !regex) || // Case 1: No maxLength, no regex
(maxLength && !regex && newValue.length === parseInt(maxLength)) || // Case 2: maxLength only
(maxLength && !regex && newValue.length <= parseInt(maxLength)) || // Case 2: maxLength only
(!maxLength && regex && regex.test(newValue)) || // Case 3: regex only
(maxLength &&
regex &&
newValue.length === parseInt(maxLength) &&
newValue.length <= parseInt(maxLength) &&
regex.test(newValue)); // Case 4: Both maxLength and regex

props.isBtnDisabled(!isValidInput);
Expand All @@ -106,7 +103,7 @@ const InputWithPrefix = (props) => {
const maxLength = idProperties.maxLength;
const regex = idProperties.regex ? new RegExp(idProperties.regex) : null;
setIsValid(
(!maxLength || e.target.value.trim().length === parseInt(maxLength)) &&
(!maxLength || e.target.value.trim().length <= parseInt(maxLength)) &&
(!regex || regex.test(e.target.value.trim()))
);
};
Expand Down
13 changes: 5 additions & 8 deletions oidc-ui/src/components/L1Biometrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,8 @@ export default function L1Biometrics({
const regex = idProperties.regex ? new RegExp(idProperties.regex) : null;
const trimmedValue = e.target.value.trim();

let newValue = regex
let newValue = regex && regex.test(trimmedValue)
? trimmedValue
.split("")
.filter((char) => regex.test(char))
.join("")
: trimmedValue;

setIndividualId(newValue); // Update state with the visible valid value
Expand All @@ -142,11 +139,11 @@ export default function L1Biometrics({
!(
(
(!maxLength && !regex) || // Case 1: No maxLength, no regex
(maxLength && !regex && newValue.length === parseInt(maxLength)) || // Case 2: maxLength only
(maxLength && !regex && newValue.length <= parseInt(maxLength)) || // Case 2: maxLength only
(!maxLength && regex && regex.test(newValue)) || // Case 3: regex only
(maxLength &&
regex &&
newValue.length === parseInt(maxLength) &&
newValue.length <= parseInt(maxLength) &&
regex.test(newValue))
) // Case 4: Both maxLength and regex
)
Expand All @@ -161,7 +158,7 @@ export default function L1Biometrics({
const maxLength = idProperties.maxLength;
const regex = idProperties.regex ? new RegExp(idProperties.regex) : null;
setIsValid(
(!maxLength || e.target.value.trim().length === parseInt(maxLength)) &&
(!maxLength || e.target.value.trim().length <= parseInt(maxLength)) &&
(!regex || regex.test(e.target.value.trim()))
);
};
Expand Down Expand Up @@ -386,7 +383,7 @@ export default function L1Biometrics({
}
propChange({
disable:
!individualId?.trim() ||
!individualId ||
isBtnDisabled ||
(showCaptcha && captchaToken === null),
onCapture: (e) => authenticateBiometricResponse(e),
Expand Down
13 changes: 5 additions & 8 deletions oidc-ui/src/components/OtpGet.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,8 @@ export default function OtpGet({
const regex = idProperties.regex ? new RegExp(idProperties.regex) : null;
const trimmedValue = e.target.value.trim();

let newValue = regex
let newValue = regex && regex.test(trimmedValue)
? trimmedValue
.split("")
.filter((char) => regex.test(char))
.join("")
: trimmedValue;

setIndividualId(newValue); // Update state with the visible valid value
Expand All @@ -141,11 +138,11 @@ export default function OtpGet({
!(
(
(!maxLength && !regex) || // Case 1: No maxLength, no regex
(maxLength && !regex && newValue.length === parseInt(maxLength)) || // Case 2: maxLength only
(maxLength && !regex && newValue.length <= parseInt(maxLength)) || // Case 2: maxLength only
(!maxLength && regex && regex.test(newValue)) || // Case 3: regex only
(maxLength &&
regex &&
newValue.length === parseInt(maxLength) &&
newValue.length <= parseInt(maxLength) &&
regex.test(newValue))
) // Case 4: Both maxLength and regex
)
Expand All @@ -160,7 +157,7 @@ export default function OtpGet({
const maxLength = idProperties.maxLength;
const regex = idProperties.regex ? new RegExp(idProperties.regex) : null;
setIsValid(
(!maxLength || e.target.value.trim().length === parseInt(maxLength)) &&
(!maxLength || e.target.value.trim().length <= parseInt(maxLength)) &&
(!regex || regex.test(e.target.value.trim()))
);
};
Expand Down Expand Up @@ -342,7 +339,7 @@ export default function OtpGet({
handleClick={sendOTP}
id="get_otp"
disabled={
!individualId?.trim() ||
!individualId ||
isBtnDisabled ||
(showCaptcha && captchaToken === null)
}
Expand Down
13 changes: 5 additions & 8 deletions oidc-ui/src/components/Password.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,8 @@ export default function Password({
const regex = idProperties.regex ? new RegExp(idProperties.regex) : null;
const trimmedValue = e.target.value.trim();

let newValue = regex
let newValue = regex && regex.test(trimmedValue)
? trimmedValue
.split("")
.filter((char) => regex.test(char))
.join("")
: trimmedValue;

setIndividualId(newValue); // Update state with the visible valid value
Expand All @@ -138,11 +135,11 @@ export default function Password({
!(
(
(!maxLength && !regex) || // Case 1: No maxLength, no regex
(maxLength && !regex && newValue.length === parseInt(maxLength)) || // Case 2: maxLength only
(maxLength && !regex && newValue.length <= parseInt(maxLength)) || // Case 2: maxLength only
(!maxLength && regex && regex.test(newValue)) || // Case 3: regex only
(maxLength &&
regex &&
newValue.length === parseInt(maxLength) &&
newValue.length <= parseInt(maxLength) &&
regex.test(newValue))
) // Case 4: Both maxLength and regex
)
Expand All @@ -157,7 +154,7 @@ export default function Password({
const maxLength = idProperties.maxLength;
const regex = idProperties.regex ? new RegExp(idProperties.regex) : null;
setIsValid(
(!maxLength || e.target.value.trim().length === parseInt(maxLength)) &&
(!maxLength || e.target.value.trim().length <= parseInt(maxLength)) &&
(!regex || regex.test(e.target.value.trim()))
);
};
Expand Down Expand Up @@ -497,7 +494,7 @@ export default function Password({
id="verify_password"
className="mt-2"
disabled={
!individualId?.trim() ||
!individualId ||
!password?.trim() ||
isBtnDisabled ||
(inputErrorBanner && inputErrorBanner.length > 0) ||
Expand Down
13 changes: 5 additions & 8 deletions oidc-ui/src/components/Pin.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,8 @@ export default function Pin({
const regex = idProperties.regex ? new RegExp(idProperties.regex) : null;
const trimmedValue = e.target.value.trim();

let newValue = regex
let newValue = regex && regex.test(trimmedValue)
? trimmedValue
.split("")
.filter((char) => regex.test(char))
.join("")
: trimmedValue;

setIndividualId(newValue); // Update state with the visible valid value
Expand All @@ -134,11 +131,11 @@ export default function Pin({
!(
(
(!maxLength && !regex) || // Case 1: No maxLength, no regex
(maxLength && !regex && newValue.length === parseInt(maxLength)) || // Case 2: maxLength only
(maxLength && !regex && newValue.length <= parseInt(maxLength)) || // Case 2: maxLength only
(!maxLength && regex && regex.test(newValue)) || // Case 3: regex only
(maxLength &&
regex &&
newValue.length === parseInt(maxLength) &&
newValue.length <= parseInt(maxLength) &&
regex.test(newValue))
) // Case 4: Both maxLength and regex
)
Expand All @@ -153,7 +150,7 @@ export default function Pin({
const maxLength = idProperties.maxLength;
const regex = idProperties.regex ? new RegExp(idProperties.regex) : null;
setIsValid(
(!maxLength || e.target.value.trim().length === parseInt(maxLength)) &&
(!maxLength || e.target.value.trim().length <= parseInt(maxLength)) &&
(!regex || regex.test(e.target.value.trim()))
);
};
Expand Down Expand Up @@ -463,7 +460,7 @@ export default function Pin({
text={t1("login")}
id="verify_pin"
disabled={
!individualId?.trim() ||
!individualId ||
!pin?.trim() ||
isBtnDisabled ||
(inputError && inputError.length > 0) ||
Expand Down

0 comments on commit f2f3bbf

Please sign in to comment.