Fix: Improve PR number validation and warning messages in input handling (#939)

* Fix: Improve PR number validation and warning messages in input handling

* Fix: Enhance PR number validation with improved sanitization and warning messages

* Fix: Change sanitizeForWarning to a local function for better encapsulation
This commit is contained in:
Chiranjib Swain
2026-06-22 16:16:37 -05:00
committed by GitHub
parent f27b608878
commit f612d9ad18
3 changed files with 218 additions and 6 deletions
+16 -3
View File
@@ -4,6 +4,13 @@ import * as github from '@actions/github';
const getPrNumberFromContext = () =>
github.context.payload.pull_request?.number;
const sanitizeForWarning = (value: string): string => {
return value.replace(
/[\x00-\x1F\x7F-\x9F]/g,
c => `\\x${c.charCodeAt(0).toString(16).padStart(2, '0')}`
);
};
export const getPrNumbers = (): number[] => {
const prInput = core.getMultilineInput('pr-number');
@@ -14,10 +21,16 @@ export const getPrNumbers = (): number[] => {
const result: number[] = [];
for (const line of prInput) {
const prNumber = parseInt(line, 10);
const trimmed = line.trim();
const prNumber = parseInt(trimmed, 10);
if (isNaN(prNumber) && prNumber <= 0) {
core.warning(`'${prNumber}' is not a valid pull request number`);
if (isNaN(prNumber) || prNumber <= 0 || String(prNumber) !== trimmed) {
const sanitized = sanitizeForWarning(line);
const hint =
sanitized !== line
? ' (non-printable characters were escaped as \\xNN)'
: '';
core.warning(`'${sanitized}' is not a valid pull request number${hint}`);
continue;
}