mirror of
https://github.com/actions/labeler
synced 2026-09-04 11:05:09 +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:
Vendored
+11
-3
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user