Provide shell and escape options when formatting matching files

This commit is contained in:
Michal Dorner 2020-12-13 21:07:47 +01:00
parent ada1eee648
commit e4d886f503
No known key found for this signature in database
GPG key ID: 9EEE04B48DA36786
7 changed files with 124 additions and 47 deletions

40
dist/index.js vendored
View file

@ -4641,9 +4641,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs = __importStar(__webpack_require__(747));
const core = __importStar(__webpack_require__(470));
@ -4651,7 +4648,7 @@ const github = __importStar(__webpack_require__(469));
const filter_1 = __webpack_require__(235);
const file_1 = __webpack_require__(258);
const git = __importStar(__webpack_require__(136));
const shell_escape_1 = __importDefault(__webpack_require__(751));
const shell_escape_1 = __webpack_require__(751);
async function run() {
try {
const workingDirectory = core.getInput('working-directory', { required: false });
@ -4819,14 +4816,16 @@ function serializeExport(files, format) {
switch (format) {
case 'json':
return JSON.stringify(fileNames);
case 'escape':
return fileNames.map(shell_escape_1.escape).join(' ');
case 'shell':
return fileNames.map(shell_escape_1.default).join(' ');
return fileNames.map(shell_escape_1.shellEscape).join(' ');
default:
return '';
}
}
function isExportFormat(value) {
return value === 'none' || value === 'shell' || value === 'json';
return value === 'none' || value === 'shell' || value === 'json' || value === 'escape';
}
run();
@ -15223,12 +15222,33 @@ module.exports = require("fs");
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// Uses easy safe set of characters which can be left unescaped to keep it readable.
// Every other character will be backslash-escaped
function shellEscape(value) {
exports.shellEscape = exports.escape = void 0;
// Backslash escape every character except small subset of definitely safe characters
function escape(value) {
return value.replace(/([^a-zA-Z0-9,._+:@%/-])/gm, '\\$1');
}
exports.default = shellEscape;
exports.escape = escape;
// Returns filename escaped for usage as shell argument.
// Applies "human readable" approach with as few escaping applied as possible
function shellEscape(value) {
if (value === '')
return value;
// Only safe characters
if (/^[a-zA-Z0-9,._+:@%/-]+$/m.test(value)) {
return value;
}
if (value.includes("'")) {
// Only safe characters, single quotes and white-spaces
if (/^[a-zA-Z0-9,._+:@%/'\s-]+$/m.test(value)) {
return `"${value}"`;
}
// Split by single quote and apply escaping recursively
return value.split("'").map(shellEscape).join("\\'");
}
// Contains some unsafe characters but no single quote
return `'${value}'`;
}
exports.shellEscape = shellEscape;
/***/ }),