Harden action metadata parsing

This commit is contained in:
copilot-swe-agent[bot] 2026-07-27 02:42:26 +00:00 committed by GitHub
parent d0cafc58c4
commit a0ff657b74
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 22 additions and 9 deletions

View File

@ -92709,6 +92709,7 @@ function getNodeVersionFromFile(versionFilePath) {
catch {
core.info('Node version file is not JSON file');
}
const nodePrefix = 'node';
let inRunsSection = false;
for (const line of contents.split(/\r?\n/)) {
const trimmedLine = line.trim();
@ -92724,7 +92725,8 @@ function getNodeVersionFromFile(versionFilePath) {
break;
}
const separatorIndex = trimmedLine.indexOf(':');
if (trimmedLine.slice(0, separatorIndex) !== 'using') {
if (separatorIndex <= 0 ||
trimmedLine.slice(0, separatorIndex) !== 'using') {
continue;
}
let runtime = trimmedLine.slice(separatorIndex + 1).trim();
@ -92733,8 +92735,9 @@ function getNodeVersionFromFile(versionFilePath) {
(runtime.startsWith('"') && runtime.endsWith('"'))) {
runtime = runtime.slice(1, -1);
}
if (runtime.startsWith('node') && /^\d+$/.test(runtime.slice(4))) {
return runtime.slice(4);
if (runtime.startsWith(nodePrefix) &&
/^\d+$/.test(runtime.slice(nodePrefix.length))) {
return runtime.slice(nodePrefix.length);
}
}
const found = contents.match(/^(?:node(js)?\s+)?v?(?<version>[^\s]+)$/m);

9
dist/setup/index.js vendored
View File

@ -98103,6 +98103,7 @@ function getNodeVersionFromFile(versionFilePath) {
catch {
core_info('Node version file is not JSON file');
}
const nodePrefix = 'node';
let inRunsSection = false;
for (const line of contents.split(/\r?\n/)) {
const trimmedLine = line.trim();
@ -98118,7 +98119,8 @@ function getNodeVersionFromFile(versionFilePath) {
break;
}
const separatorIndex = trimmedLine.indexOf(':');
if (trimmedLine.slice(0, separatorIndex) !== 'using') {
if (separatorIndex <= 0 ||
trimmedLine.slice(0, separatorIndex) !== 'using') {
continue;
}
let runtime = trimmedLine.slice(separatorIndex + 1).trim();
@ -98127,8 +98129,9 @@ function getNodeVersionFromFile(versionFilePath) {
(runtime.startsWith('"') && runtime.endsWith('"'))) {
runtime = runtime.slice(1, -1);
}
if (runtime.startsWith('node') && /^\d+$/.test(runtime.slice(4))) {
return runtime.slice(4);
if (runtime.startsWith(nodePrefix) &&
/^\d+$/.test(runtime.slice(nodePrefix.length))) {
return runtime.slice(nodePrefix.length);
}
}
const found = contents.match(/^(?:node(js)?\s+)?v?(?<version>[^\s]+)$/m);

View File

@ -68,6 +68,7 @@ export function getNodeVersionFromFile(versionFilePath: string): string | null {
core.info('Node version file is not JSON file');
}
const nodePrefix = 'node';
let inRunsSection = false;
for (const line of contents.split(/\r?\n/)) {
const trimmedLine = line.trim();
@ -85,7 +86,10 @@ export function getNodeVersionFromFile(versionFilePath: string): string | null {
}
const separatorIndex = trimmedLine.indexOf(':');
if (trimmedLine.slice(0, separatorIndex) !== 'using') {
if (
separatorIndex <= 0 ||
trimmedLine.slice(0, separatorIndex) !== 'using'
) {
continue;
}
@ -97,8 +101,11 @@ export function getNodeVersionFromFile(versionFilePath: string): string | null {
) {
runtime = runtime.slice(1, -1);
}
if (runtime.startsWith('node') && /^\d+$/.test(runtime.slice(4))) {
return runtime.slice(4);
if (
runtime.startsWith(nodePrefix) &&
/^\d+$/.test(runtime.slice(nodePrefix.length))
) {
return runtime.slice(nodePrefix.length);
}
}