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
+11 -3
View File
@@ -995,6 +995,9 @@ exports.getPrNumbers = void 0;
const core = __importStar(__nccwpck_require__(7484));
const github = __importStar(__nccwpck_require__(3228));
const getPrNumberFromContext = () => { var _a; return (_a = github.context.payload.pull_request) === null || _a === void 0 ? void 0 : _a.number; };
const sanitizeForWarning = (value) => {
return value.replace(/[\x00-\x1F\x7F-\x9F]/g, c => `\\x${c.charCodeAt(0).toString(16).padStart(2, '0')}`);
};
const getPrNumbers = () => {
const prInput = core.getMultilineInput('pr-number');
if (!(prInput === null || prInput === void 0 ? void 0 : prInput.length)) {
@@ -1002,9 +1005,14 @@ const getPrNumbers = () => {
}
const result = [];
for (const line of prInput) {
const prNumber = parseInt(line, 10);
if (isNaN(prNumber) && prNumber <= 0) {
core.warning(`'${prNumber}' is not a valid pull request number`);
const trimmed = line.trim();
const prNumber = parseInt(trimmed, 10);
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;
}
result.push(prNumber);