Add input validation and tests for Station names
This commit is contained in:
@@ -84,6 +84,16 @@ export function validateUuid(uuid: unknown): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
export function validateStation(station: unknown): boolean {
|
||||
if (typeof station !== "string") {
|
||||
throw new ValidationError("Invalid input: The station name should be a string");
|
||||
}
|
||||
if (!/^[A-Za-z0-9\s&'()-]+$/.test(station)) {
|
||||
throw new ValidationError("Invalid input: Station name should include letters, spaces, ', '/', '-', '&' only");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
export function validateReasonCode(code: unknown): boolean {
|
||||
if (typeof code === "number") {
|
||||
// Ensure it's a 3-digit number (100-999)
|
||||
|
||||
Reference in New Issue
Block a user