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", "First name": "John",
"Email": "john@gmail.com" "Email": "john@gmail.com"
} }
},
"textBubbleContentFormat": {
"type": "string",
"enum": [
"richText",
"markdown"
],
"default": "richText"
} }
} }
} }
@ -1441,6 +1449,14 @@
"properties": { "properties": {
"message": { "message": {
"type": "string" "type": "string"
},
"textBubbleContentFormat": {
"type": "string",
"enum": [
"richText",
"markdown"
],
"default": "richText"
} }
} }
} }
@ -1855,6 +1871,14 @@
"sessionId": { "sessionId": {
"type": "string", "type": "string",
"description": "If provided, will be used as the session ID and will overwrite any existing session with the same ID." "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": { "content": {
"type": "object", "oneOf": [
"properties": { {
"html": { "type": "object",
"type": "string" "properties": {
"type": {
"type": "string",
"enum": [
"richText"
]
},
"richText": {}
},
"required": [
"type"
]
}, },
"richText": { {
"type": "array", "type": "object",
"items": {} "properties": {
}, "type": {
"plainText": { "type": "string",
"type": "string" "enum": [
"markdown"
]
},
"markdown": {
"type": "string"
}
},
"required": [
"type",
"markdown"
]
} }
} ]
} }
}, },
"required": [ "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[] variables: Variable[]
} }
) => { ) => {
if (inputValue === '') return false
const parsedNumber = Number(inputValue)
if (isNaN(parsedNumber)) return false
const min = const min =
options?.min && typeof options.min === 'string' options?.min && typeof options.min === 'string'
? Number(parseVariables(variables)(options.min)) ? Number(parseVariables(variables)(options.min))
@ -20,10 +25,8 @@ export const validateNumber = (
options?.min && typeof options.min === 'string' options?.min && typeof options.min === 'string'
? Number(parseVariables(variables)(options.min)) ? Number(parseVariables(variables)(options.min))
: undefined : undefined
return ( return (
inputValue !== '' && (isNotDefined(min) || parsedNumber >= min) &&
(isNotDefined(min) || Number(inputValue) >= min) && (isNotDefined(max) || parsedNumber <= max)
(isNotDefined(max) || Number(inputValue) <= max)
) )
} }

View File

@ -8,6 +8,7 @@
"scripts": { "scripts": {
"dev": "dotenv -e ./.env -e ../../.env -- tsx scripts/studio.ts", "dev": "dotenv -e ./.env -e ../../.env -- tsx scripts/studio.ts",
"db:generate": "dotenv -e ./.env -e ../../.env -- tsx scripts/db-generate.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", "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: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", "migrate:dev": "dotenv -e ./.env -e ../../.env -- prisma migrate dev --create-only --schema postgresql/schema.prisma",