2
0

🚸 (number) Avoid parsing numbers starting with 0

This commit is contained in:
Baptiste Arnaud
2024-05-27 10:36:30 +02:00
parent e1f1b58c1c
commit 3e4e7531f6
4 changed files with 69 additions and 16 deletions

View File

@ -1082,6 +1082,14 @@
"First name": "John",
"Email": "john@gmail.com"
}
},
"textBubbleContentFormat": {
"type": "string",
"enum": [
"richText",
"markdown"
],
"default": "richText"
}
}
}
@ -1441,6 +1449,14 @@
"properties": {
"message": {
"type": "string"
},
"textBubbleContentFormat": {
"type": "string",
"enum": [
"richText",
"markdown"
],
"default": "richText"
}
}
}
@ -1855,6 +1871,14 @@
"sessionId": {
"type": "string",
"description": "If provided, will be used as the session ID and will overwrite any existing session with the same ID."
},
"textBubbleContentFormat": {
"type": "string",
"enum": [
"richText",
"markdown"
],
"default": "richText"
}
}
}
@ -11879,19 +11903,41 @@
]
},
"content": {
"type": "object",
"properties": {
"html": {
"type": "string"
"oneOf": [
{
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": [
"richText"
]
},
"richText": {}
},
"required": [
"type"
]
},
"richText": {
"type": "array",
"items": {}
},
"plainText": {
"type": "string"
{
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": [
"markdown"
]
},
"markdown": {
"type": "string"
}
},
"required": [
"type",
"markdown"
]
}
}
]
}
},
"required": [

View File

@ -1 +1,4 @@
export const parseNumber = (value: string) => Number(value).toString()
export const parseNumber = (value: string) => {
if (value.startsWith('0')) return value
return parseFloat(value).toString()
}

View File

@ -12,6 +12,11 @@ export const validateNumber = (
variables: Variable[]
}
) => {
if (inputValue === '') return false
const parsedNumber = Number(inputValue)
if (isNaN(parsedNumber)) return false
const min =
options?.min && typeof options.min === 'string'
? Number(parseVariables(variables)(options.min))
@ -20,10 +25,8 @@ export const validateNumber = (
options?.min && typeof options.min === 'string'
? Number(parseVariables(variables)(options.min))
: undefined
return (
inputValue !== '' &&
(isNotDefined(min) || Number(inputValue) >= min) &&
(isNotDefined(max) || Number(inputValue) <= max)
(isNotDefined(min) || parsedNumber >= min) &&
(isNotDefined(max) || parsedNumber <= max)
)
}

View File

@ -8,6 +8,7 @@
"scripts": {
"dev": "dotenv -e ./.env -e ../../.env -- tsx scripts/studio.ts",
"db:generate": "dotenv -e ./.env -e ../../.env -- tsx scripts/db-generate.ts",
"db:generate:mysql": "DATABASE_URL=mysql:// dotenv -e ./.env -e ../../.env -- tsx scripts/db-generate.ts",
"db:push": "dotenv -e ./.env -e ../../.env -- tsx scripts/db-push.ts",
"migrate:deploy": "dotenv -e ./.env -e ../../.env -- tsx scripts/migrate-deploy.ts",
"migrate:dev": "dotenv -e ./.env -e ../../.env -- prisma migrate dev --create-only --schema postgresql/schema.prisma",