diff --git a/src/bin/keycloakify/generateFtl/ftl_object_to_js_code_declaring_an_object.ftl b/src/bin/keycloakify/generateFtl/ftl_object_to_js_code_declaring_an_object.ftl index 96ae339a..95eed751 100644 --- a/src/bin/keycloakify/generateFtl/ftl_object_to_js_code_declaring_an_object.ftl +++ b/src/bin/keycloakify/generateFtl/ftl_object_to_js_code_declaring_an_object.ftl @@ -528,12 +528,23 @@ <#return '"' + object?datetime?iso_utc + '"'> + <#local isNumber = ""> + <#attempt> + <#local isNumber = object?is_number> + <#recover> + <#return "ABORT: Can't test if it's a number"> + + + <#if isNumber> + <#return object?c> + + <#attempt> <#return '"' + object?js_string + '"'>; <#recover> - <#return "ABORT: Couldn't convert into string non hash, non method, non boolean, non enumerable object"> + <#return "ABORT: Couldn't convert into string non hash, non method, non boolean, non number, non enumerable object"> <#function is_subpath path searchedPath> diff --git a/src/login/UserProfileFormFields.tsx b/src/login/UserProfileFormFields.tsx index 846cfb32..efb24163 100644 --- a/src/login/UserProfileFormFields.tsx +++ b/src/login/UserProfileFormFields.tsx @@ -332,9 +332,13 @@ function InputTag(props: InputFiledByTypeProps & { fieldIndex: number | undefine autoComplete={attribute.autocomplete} placeholder={attribute.annotations.inputTypePlaceholder} pattern={attribute.annotations.inputTypePattern} - size={attribute.annotations.inputTypeSize === undefined ? undefined : parseInt(attribute.annotations.inputTypeSize)} - maxLength={attribute.annotations.inputTypeMaxlength === undefined ? undefined : parseInt(attribute.annotations.inputTypeMaxlength)} - minLength={attribute.annotations.inputTypeMinlength === undefined ? undefined : parseInt(attribute.annotations.inputTypeMinlength)} + size={attribute.annotations.inputTypeSize === undefined ? undefined : parseInt(`${attribute.annotations.inputTypeSize}`)} + maxLength={ + attribute.annotations.inputTypeMaxlength === undefined ? undefined : parseInt(`${attribute.annotations.inputTypeMaxlength}`) + } + minLength={ + attribute.annotations.inputTypeMinlength === undefined ? undefined : parseInt(`${attribute.annotations.inputTypeMinlength}`) + } max={attribute.annotations.inputTypeMax} min={attribute.annotations.inputTypeMin} step={attribute.annotations.inputTypeStep} @@ -428,7 +432,7 @@ function AddRemoveButtonsMultiValuedAttribute(props: { return undefined; } - return parseInt(minStr); + return parseInt(`${minStr}`); })(); if (minCount === undefined) { @@ -460,7 +464,7 @@ function AddRemoveButtonsMultiValuedAttribute(props: { return undefined; } - return parseInt(maxStr); + return parseInt(`${maxStr}`); })(); if (maxCount === undefined) { @@ -635,9 +639,9 @@ function TextareaTag(props: InputFiledByTypeProps) { className={getClassName("kcInputClass")} aria-invalid={displayableErrors.length !== 0} disabled={attribute.readOnly} - cols={attribute.annotations.inputTypeCols === undefined ? undefined : parseInt(attribute.annotations.inputTypeCols)} - rows={attribute.annotations.inputTypeRows === undefined ? undefined : parseInt(attribute.annotations.inputTypeRows)} - maxLength={attribute.annotations.inputTypeMaxlength === undefined ? undefined : parseInt(attribute.annotations.inputTypeMaxlength)} + cols={attribute.annotations.inputTypeCols === undefined ? undefined : parseInt(`${attribute.annotations.inputTypeCols}`)} + rows={attribute.annotations.inputTypeRows === undefined ? undefined : parseInt(`${attribute.annotations.inputTypeRows}`)} + maxLength={attribute.annotations.inputTypeMaxlength === undefined ? undefined : parseInt(`${attribute.annotations.inputTypeMaxlength}`)} value={value} onChange={event => formValidationDispatch({ @@ -672,7 +676,7 @@ function SelectTag(props: InputFiledByTypeProps) { aria-invalid={displayableErrors.length !== 0} disabled={attribute.readOnly} multiple={isMultiple} - size={attribute.annotations.inputTypeSize === undefined ? undefined : parseInt(attribute.annotations.inputTypeSize)} + size={attribute.annotations.inputTypeSize === undefined ? undefined : parseInt(`${attribute.annotations.inputTypeSize}`)} value={valueOrValues} onChange={event => formValidationDispatch({ diff --git a/src/login/kcContext/KcContext.ts b/src/login/kcContext/KcContext.ts index 86bc68cf..5885e997 100644 --- a/src/login/kcContext/KcContext.ts +++ b/src/login/kcContext/KcContext.ts @@ -556,18 +556,18 @@ export type Attribute = { validators: Validators; annotations: { inputType?: string; - inputTypeSize?: `${number}`; + inputTypeSize?: `${number}` | number; inputOptionsFromValidation?: string; inputOptionLabels?: Record; inputOptionLabelsI18nPrefix?: string; - inputTypeCols?: `${number}`; - inputTypeRows?: `${number}`; - inputTypeMaxlength?: `${number}`; + inputTypeCols?: `${number}` | number; + inputTypeRows?: `${number}` | number; + inputTypeMaxlength?: `${number}` | number; inputHelperTextBefore?: string; inputHelperTextAfter?: string; inputTypePlaceholder?: string; inputTypePattern?: string; - inputTypeMinlength?: `${number}`; + inputTypeMinlength?: `${number}` | number; inputTypeMax?: string; inputTypeMin?: string; inputTypeStep?: string; @@ -666,9 +666,8 @@ export declare namespace Validators { }; export type Range = { - /** "0", "1", "2"... yeah I know, don't tell me */ - min?: `${number}`; - max?: `${number}`; + min?: `${number}` | number; + max?: `${number}` | number; }; export type Options = { options: string[]; @@ -688,15 +687,15 @@ export declare namespace Validators { export type PasswordPolicies = { /** The minimum length of the password */ - length?: `${number}`; + length?: number; /** The minimum number of digits required in the password */ - digits?: `${number}`; + digits?: number; /** The minimum number of lowercase characters required in the password */ - lowerCase?: `${number}`; + lowerCase?: number; /** The minimum number of uppercase characters required in the password */ - upperCase?: `${number}`; + upperCase?: number; /** The minimum number of special characters required in the password */ - specialChars?: `${number}`; + specialChars?: number; /** Whether the password can be the username */ notUsername?: boolean; /** Whether the password can be the email address */ diff --git a/src/login/lib/useUserProfileForm.tsx b/src/login/lib/useUserProfileForm.tsx index fb5710da..d82fad18 100644 --- a/src/login/lib/useUserProfileForm.tsx +++ b/src/login/lib/useUserProfileForm.tsx @@ -315,7 +315,7 @@ export function useUserProfileForm(params: ParamsOfUseUserProfileForm): ReturnTy break apply_validator_min_range; } - const min = parseInt(minStr); + const min = parseInt(`${minStr}`); for (let index = values.length; index < min; index++) { values.push(""); @@ -674,13 +674,13 @@ function useGetErrors(params: { kcContext: Pick= minLength) { break check_password_policy_x; @@ -761,9 +759,7 @@ function useGetErrors(params: { kcContext: Pick !isNaN(parseInt(char))).length >= minNumberOfDigits) { break check_password_policy_x; @@ -791,9 +787,7 @@ function useGetErrors(params: { kcContext: Pick char === char.toLowerCase() && char !== char.toUpperCase()).length >= minNumberOfLowerCaseChar @@ -823,9 +817,7 @@ function useGetErrors(params: { kcContext: Pick char === char.toUpperCase() && char !== char.toLowerCase()).length >= minNumberOfUpperCaseChar @@ -855,9 +847,7 @@ function useGetErrors(params: { kcContext: Pick !char.match(/[a-zA-Z0-9]/)).length >= minNumberOfSpecialChar) { break check_password_policy_x; @@ -1041,8 +1031,8 @@ function useGetErrors(params: { kcContext: Pick parseInt(max)) { - const msgArgs = ["error-invalid-length-too-long", max] as const; + if (max !== undefined && value.length > parseInt(`${max}`)) { + const msgArgs = ["error-invalid-length-too-long", `${max}`] as const; errors.push({ "errorMessage": {msg(...msgArgs)}, @@ -1052,8 +1042,8 @@ function useGetErrors(params: { kcContext: Pick{msg(...msgArgs)}, @@ -1170,8 +1160,8 @@ function useGetErrors(params: { kcContext: Pick parseInt(max)) { - const msgArgs = ["error-number-out-of-range-too-big", max] as const; + if (max !== undefined && intValue > parseInt(`${max}`)) { + const msgArgs = ["error-number-out-of-range-too-big", `${max}`] as const; errors.push({ "errorMessage": {msg(...msgArgs)}, @@ -1183,8 +1173,8 @@ function useGetErrors(params: { kcContext: Pick{msg(...msgArgs)},