[fabric/validations] Update string sanitization to return undefined for non-string values

This commit is contained in:
Pablo Baleztena 2024-10-23 23:54:46 -03:00
parent 6329044415
commit f30535055f
2 changed files with 4 additions and 4 deletions

View File

@ -17,13 +17,13 @@ describe("Sanitize String", () => {
test("Given a number value it should convert it to a string", () => { test("Given a number value it should convert it to a string", () => {
const sanitized = parseAndSanitizeString(123); const sanitized = parseAndSanitizeString(123);
expect(sanitized).toBe("123"); expect(sanitized).toBe(undefined);
}); });
test("Given a boolean value it should convert it to a string", () => { test("Given a boolean value it should convert it to a string", () => {
const sanitized = parseAndSanitizeString(true); const sanitized = parseAndSanitizeString(true);
expect(sanitized).toBe("true"); expect(sanitized).toBe(undefined);
}); });
test("Given a null value it should return null", () => { test("Given a null value it should return null", () => {

View File

@ -7,8 +7,8 @@ import { isNullish } from "../nullish/is-nullish.ts";
export function parseAndSanitizeString( export function parseAndSanitizeString(
value: unknown, value: unknown,
): string | undefined { ): string | undefined {
if (isNullish(value)) return undefined; if (isNullish(value) || typeof value != "string") return undefined;
return stripLow((String(value)).trim()); return stripLow(value).trim();
} }
// deno-lint-ignore no-control-regex // deno-lint-ignore no-control-regex