mirror of
https://github.com/actions/labeler
synced 2026-09-24 14:41:50 +02:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user