From 96e15838db7a65cd1c37f77e81bedf2461c0a168 Mon Sep 17 00:00:00 2001 From: "vitalii.semianchuk" Date: Mon, 6 Jul 2026 21:09:05 +0100 Subject: [PATCH] fix: numeric validator accepts "123abc", truncate exceeds maxLength - the numeric validation used parseFloat which parses "123abc" as 123 and passes validation. changed to Number() which correctly returns NaN for strings with trailing non-numeric characters. - truncate directive produced strings longer than maxLength because the suffix length wasn't subtracted from the slice. "hello world" truncated to length 8 with "..." suffix became 11 chars instead of 8. --- packages/core/src/validation.ts | 2 +- packages/directives/src/truncate.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/core/src/validation.ts b/packages/core/src/validation.ts index fd9c20e8..9e699751 100644 --- a/packages/core/src/validation.ts +++ b/packages/core/src/validation.ts @@ -153,7 +153,7 @@ export const builtInValidationFunctions: Record = { */ numeric: (value: unknown) => { if (typeof value === "number") return !isNaN(value); - if (typeof value === "string") return !isNaN(parseFloat(value)); + if (typeof value === "string") return !isNaN(Number(value)) && isFinite(Number(value)); return false; }, diff --git a/packages/directives/src/truncate.ts b/packages/directives/src/truncate.ts index 822ce477..05fd7c6d 100644 --- a/packages/directives/src/truncate.ts +++ b/packages/directives/src/truncate.ts @@ -16,6 +16,6 @@ export const truncateDirective = defineDirective({ const suffix = raw.suffix ?? "..."; if (text.length <= maxLength) return text; - return text.slice(0, maxLength) + suffix; + return text.slice(0, maxLength - suffix.length) + suffix; }, });