Architecture validation for JDK file installs (#1324)

* Enhance architecture validation and error handling

* Improve architecture normalization and validation for custom tokens

* Refactor architecture validation to consolidate error handling for invalid tokens
This commit is contained in:
v-mahabaleshwars
2026-11-13 23:04:15 -05:00
committed by GitHub
parent 77dd5b2ce2
commit 9ce5b12cb9
5 changed files with 67 additions and 11 deletions
+20 -4
View File
@@ -192,6 +192,9 @@ const CANONICAL_ARCHITECTURES: readonly JavaArchitecture[] = [
's390x'
];
// Used in environment-variable names and tool-cache paths.
const ARCHITECTURE_TOKEN = /^[A-Za-z0-9][A-Za-z0-9_-]*$/;
const PLATFORM_ALIASES: Readonly<
Partial<Record<NodeJS.Platform, JavaPlatform>>
> = {
@@ -204,14 +207,27 @@ const PLATFORM_ALIASES: Readonly<
export function normalizeArchitecture(architecture: string): string {
const trimmedArchitecture = architecture.trim();
const normalizedArchitecture = trimmedArchitecture.toLowerCase();
return (
ARCHITECTURE_ALIASES[normalizedArchitecture] ??
const alias = Object.prototype.hasOwnProperty.call(
ARCHITECTURE_ALIASES,
normalizedArchitecture
)
? ARCHITECTURE_ALIASES[normalizedArchitecture]
: undefined;
const result =
alias ??
(CANONICAL_ARCHITECTURES.includes(
normalizedArchitecture as JavaArchitecture
)
? normalizedArchitecture
: trimmedArchitecture)
);
: trimmedArchitecture);
if (!ARCHITECTURE_TOKEN.test(result)) {
throw new Error(
`Unsupported architecture value: ${JSON.stringify(architecture)}`
);
}
return result;
}
export function normalizePlatform(