[fabric/validations] Update string sanitization to return undefined for non-string values
This commit is contained in:
parent
6329044415
commit
f30535055f
@ -17,13 +17,13 @@ describe("Sanitize String", () => {
|
||||
test("Given a number value it should convert it to a string", () => {
|
||||
const sanitized = parseAndSanitizeString(123);
|
||||
|
||||
expect(sanitized).toBe("123");
|
||||
expect(sanitized).toBe(undefined);
|
||||
});
|
||||
|
||||
test("Given a boolean value it should convert it to a string", () => {
|
||||
const sanitized = parseAndSanitizeString(true);
|
||||
|
||||
expect(sanitized).toBe("true");
|
||||
expect(sanitized).toBe(undefined);
|
||||
});
|
||||
|
||||
test("Given a null value it should return null", () => {
|
||||
|
||||
@ -7,8 +7,8 @@ import { isNullish } from "../nullish/is-nullish.ts";
|
||||
export function parseAndSanitizeString(
|
||||
value: unknown,
|
||||
): string | undefined {
|
||||
if (isNullish(value)) return undefined;
|
||||
return stripLow((String(value)).trim());
|
||||
if (isNullish(value) || typeof value != "string") return undefined;
|
||||
return stripLow(value).trim();
|
||||
}
|
||||
|
||||
// deno-lint-ignore no-control-regex
|
||||
|
||||
Loading…
Reference in New Issue
Block a user