diff options
author | Elizabeth Alexander Hunt <me@liz.coffee> | 2025-05-13 09:50:15 -0700 |
---|---|---|
committer | Elizabeth Alexander Hunt <me@liz.coffee> | 2025-05-13 09:50:15 -0700 |
commit | 2543ac8b11af11f034836591046cdb52911f9403 (patch) | |
tree | d2fa475348c9867aab2994e9914895a57db88d75 /utils/validate_identifier.ts | |
parent | e49fda41176d025a671802be76c219d66167276f (diff) | |
download | ci-2543ac8b11af11f034836591046cdb52911f9403.tar.gz ci-2543ac8b11af11f034836591046cdb52911f9403.zip |
snapshot
Diffstat (limited to 'utils/validate_identifier.ts')
-rw-r--r-- | utils/validate_identifier.ts | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/utils/validate_identifier.ts b/utils/validate_identifier.ts index e2a1dc5..ec8b77b 100644 --- a/utils/validate_identifier.ts +++ b/utils/validate_identifier.ts @@ -1,11 +1,17 @@ +import { Either } from "./mod.ts"; + export const validateIdentifier = (token: string) => { return (/^[a-zA-Z0-9_\-:. \/]+$/).test(token) && !token.includes(".."); }; -export const invalidExecutionEntriesOf = ( +// ensure {@param obj} is a Record<string, string> with stuff that won't +// have the potential for shell injection, just to be super safe. +export const validateExecutionEntries = ( obj: Record<string, unknown>, -): Array<[string, unknown]> => { - return Object.entries(obj).filter((e) => +): Either<Array<[string, unknown]>, Record<string, string>> => { + const invalidEntries = Object.entries(obj).filter((e) => !e.every((x) => typeof x === "string" && validateIdentifier(x)) ); + if (invalidEntries.length > 0) return Either.left(invalidEntries); + return Either.right(<Record<string, string>> obj); }; |