Fix ftl template not correctly parsing numbers

This commit is contained in:
Joseph Garrone 2024-05-11 16:06:42 +02:00
parent 632641a067
commit 18c82a58a7
4 changed files with 53 additions and 49 deletions

View File

@ -528,12 +528,23 @@
<#return '"' + object?datetime?iso_utc + '"'>
</#if>
<#local isNumber = "">
<#attempt>
<#local isNumber = object?is_number>
<#recover>
<#return "ABORT: Can't test if it's a number">
</#attempt>
<#if isNumber>
<#return object?c>
</#if>
<#attempt>
<#return '"' + object?js_string + '"'>;
<#recover>
</#attempt>
<#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>
<#function is_subpath path searchedPath>

View File

@ -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({

View File

@ -556,18 +556,18 @@ export type Attribute = {
validators: Validators;
annotations: {
inputType?: string;
inputTypeSize?: `${number}`;
inputTypeSize?: `${number}` | number;
inputOptionsFromValidation?: string;
inputOptionLabels?: Record<string, string | undefined>;
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 */

View File

@ -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<KcContextLike, "messagesPerField
const { min: minStr } = validator;
const min = minStr !== undefined ? parseInt(minStr) : attribute.required ? 1 : 0;
const min = minStr !== undefined ? parseInt(`${minStr}`) : attribute.required ? 1 : 0;
assert(!isNaN(min));
const { max: maxStr } = validator;
const max = maxStr === undefined ? Infinity : parseInt(maxStr);
const max = maxStr === undefined ? Infinity : parseInt(`${maxStr}`);
assert(!isNaN(max));
@ -731,9 +731,7 @@ function useGetErrors(params: { kcContext: Pick<KcContextLike, "messagesPerField
break check_password_policy_x;
}
const minLength = parseInt(policy);
assert(!isNaN(minLength));
const minLength = policy;
if (value.length >= minLength) {
break check_password_policy_x;
@ -761,9 +759,7 @@ function useGetErrors(params: { kcContext: Pick<KcContextLike, "messagesPerField
break check_password_policy_x;
}
const minNumberOfDigits = parseInt(policy);
assert(!isNaN(minNumberOfDigits));
const minNumberOfDigits = policy;
if (value.split("").filter(char => !isNaN(parseInt(char))).length >= minNumberOfDigits) {
break check_password_policy_x;
@ -791,9 +787,7 @@ function useGetErrors(params: { kcContext: Pick<KcContextLike, "messagesPerField
break check_password_policy_x;
}
const minNumberOfLowerCaseChar = parseInt(policy);
assert(!isNaN(minNumberOfLowerCaseChar));
const minNumberOfLowerCaseChar = policy;
if (
value.split("").filter(char => char === char.toLowerCase() && char !== char.toUpperCase()).length >= minNumberOfLowerCaseChar
@ -823,9 +817,7 @@ function useGetErrors(params: { kcContext: Pick<KcContextLike, "messagesPerField
break check_password_policy_x;
}
const minNumberOfUpperCaseChar = parseInt(policy);
assert(!isNaN(minNumberOfUpperCaseChar));
const minNumberOfUpperCaseChar = policy;
if (
value.split("").filter(char => char === char.toUpperCase() && char !== char.toLowerCase()).length >= minNumberOfUpperCaseChar
@ -855,9 +847,7 @@ function useGetErrors(params: { kcContext: Pick<KcContextLike, "messagesPerField
break check_password_policy_x;
}
const minNumberOfSpecialChar = parseInt(policy);
assert(!isNaN(minNumberOfSpecialChar));
const minNumberOfSpecialChar = policy;
if (value.split("").filter(char => !char.match(/[a-zA-Z0-9]/)).length >= minNumberOfSpecialChar) {
break check_password_policy_x;
@ -1041,8 +1031,8 @@ function useGetErrors(params: { kcContext: Pick<KcContextLike, "messagesPerField
"name": validatorName
};
if (max !== undefined && value.length > 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": <Fragment key={`${attributeName}-${errors.length}`}>{msg(...msgArgs)}</Fragment>,
@ -1052,8 +1042,8 @@ function useGetErrors(params: { kcContext: Pick<KcContextLike, "messagesPerField
});
}
if (min !== undefined && value.length < parseInt(min)) {
const msgArgs = ["error-invalid-length-too-short", min] as const;
if (min !== undefined && value.length < parseInt(`${min}`)) {
const msgArgs = ["error-invalid-length-too-short", `${min}`] as const;
errors.push({
"errorMessage": <Fragment key={`${attributeName}-${errors.length}`}>{msg(...msgArgs)}</Fragment>,
@ -1170,8 +1160,8 @@ function useGetErrors(params: { kcContext: Pick<KcContextLike, "messagesPerField
break validator_x;
}
if (max !== undefined && intValue > 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": <Fragment key={`${attributeName}-${errors.length}`}>{msg(...msgArgs)}</Fragment>,
@ -1183,8 +1173,8 @@ function useGetErrors(params: { kcContext: Pick<KcContextLike, "messagesPerField
break validator_x;
}
if (min !== undefined && intValue < parseInt(min)) {
const msgArgs = ["error-number-out-of-range-too-small", min] as const;
if (min !== undefined && intValue < parseInt(`${min}`)) {
const msgArgs = ["error-number-out-of-range-too-small", `${min}`] as const;
errors.push({
"errorMessage": <Fragment key={`${attributeName}-${errors.length}`}>{msg(...msgArgs)}</Fragment>,