From 3ac7f4d7acd105c4415de639b562df294b8423b2 Mon Sep 17 00:00:00 2001 From: mahabaleshwars Date: Mon, 4 Mar 2024 13:36:34 +0530 Subject: [PATCH] Checked for the file extension --- dist/cleanup/index.js | 5 ++++- dist/setup/index.js | 5 ++++- src/util.ts | 5 ++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/dist/cleanup/index.js b/dist/cleanup/index.js index 0bdc0310..f8989c28 100644 --- a/dist/cleanup/index.js +++ b/dist/cleanup/index.js @@ -87893,9 +87893,12 @@ function getVersionFromFileContent(content, distributionName, versionFile) { if (versionFile == '.tool-versions') { javaVersionRegExp = /^java\s+(?:\S+-)?v?(?[^\s]+)$/m; } - else { + else if (versionFile == '.java-version') { javaVersionRegExp = /(?(?<=(^|\s|-))(\d+\S*))(\s|$)/; } + else { + throw new Error('Invalid version file'); + } const fileContent = ((_b = (_a = content.match(javaVersionRegExp)) === null || _a === void 0 ? void 0 : _a.groups) === null || _b === void 0 ? void 0 : _b.version) ? (_d = (_c = content.match(javaVersionRegExp)) === null || _c === void 0 ? void 0 : _c.groups) === null || _d === void 0 ? void 0 : _d.version : ''; diff --git a/dist/setup/index.js b/dist/setup/index.js index 2936d56d..bcc80163 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -125267,9 +125267,12 @@ function getVersionFromFileContent(content, distributionName, versionFile) { if (versionFile == '.tool-versions') { javaVersionRegExp = /^java\s+(?:\S+-)?v?(?[^\s]+)$/m; } - else { + else if (versionFile == '.java-version') { javaVersionRegExp = /(?(?<=(^|\s|-))(\d+\S*))(\s|$)/; } + else { + throw new Error('Invalid version file'); + } const fileContent = ((_b = (_a = content.match(javaVersionRegExp)) === null || _a === void 0 ? void 0 : _a.groups) === null || _b === void 0 ? void 0 : _b.version) ? (_d = (_c = content.match(javaVersionRegExp)) === null || _c === void 0 ? void 0 : _c.groups) === null || _d === void 0 ? void 0 : _d.version : ''; diff --git a/src/util.ts b/src/util.ts index a4c77faa..4d61574e 100644 --- a/src/util.ts +++ b/src/util.ts @@ -8,6 +8,7 @@ import * as core from '@actions/core'; import * as tc from '@actions/tool-cache'; import {INPUT_JOB_STATUS, DISTRIBUTIONS_ONLY_MAJOR_VERSION} from './constants'; import {OutgoingHttpHeaders} from 'http'; +import {error} from 'console'; export function getTempDir() { const tempDirectory = process.env['RUNNER_TEMP'] || os.tmpdir(); @@ -121,8 +122,10 @@ export function getVersionFromFileContent( let javaVersionRegExp: RegExp; if (versionFile == '.tool-versions') { javaVersionRegExp = /^java\s+(?:\S+-)?v?(?[^\s]+)$/m; - } else { + } else if (versionFile == '.java-version') { javaVersionRegExp = /(?(?<=(^|\s|-))(\d+\S*))(\s|$)/; + } else { + throw new Error('Invalid version file'); } const fileContent = content.match(javaVersionRegExp)?.groups?.version