fix: update safe output regex and the docs (#1805)
Co-authored-by: jackton1 <jackton1@users.noreply.github.com> Co-authored-by: GitHub Action <action@github.com> Co-authored-by: Tonye Jack <jtonye@ymail.com>
This commit is contained in:
parent
0102c07446
commit
ff2f6e6b91
@ -572,6 +572,12 @@ Support this project with a :star:
|
|||||||
# Default: "\n"
|
# Default: "\n"
|
||||||
recover_files_separator: ''
|
recover_files_separator: ''
|
||||||
|
|
||||||
|
# Apply sanitization to output filenames before being set as
|
||||||
|
# output.
|
||||||
|
# Type: boolean
|
||||||
|
# Default: "true"
|
||||||
|
safe_output: ''
|
||||||
|
|
||||||
# Split character for output strings.
|
# Split character for output strings.
|
||||||
# Type: string
|
# Type: string
|
||||||
# Default: " "
|
# Default: " "
|
||||||
|
47
dist/index.js
generated
vendored
47
dist/index.js
generated
vendored
@ -454,7 +454,8 @@ const setOutputsAndGetModifiedAndChangedFilesStatus = ({ allDiffFiles, allFilter
|
|||||||
writeOutputFiles: inputs.writeOutputFiles,
|
writeOutputFiles: inputs.writeOutputFiles,
|
||||||
outputDir: inputs.outputDir,
|
outputDir: inputs.outputDir,
|
||||||
json: inputs.json,
|
json: inputs.json,
|
||||||
shouldEscape: inputs.escapeJson
|
shouldEscape: inputs.escapeJson,
|
||||||
|
safeOutput: inputs.safeOutput
|
||||||
});
|
});
|
||||||
yield (0, utils_1.setOutput)({
|
yield (0, utils_1.setOutput)({
|
||||||
key: (0, utils_1.getOutputKey)('added_files_count', outputPrefix),
|
key: (0, utils_1.getOutputKey)('added_files_count', outputPrefix),
|
||||||
@ -474,7 +475,8 @@ const setOutputsAndGetModifiedAndChangedFilesStatus = ({ allDiffFiles, allFilter
|
|||||||
writeOutputFiles: inputs.writeOutputFiles,
|
writeOutputFiles: inputs.writeOutputFiles,
|
||||||
outputDir: inputs.outputDir,
|
outputDir: inputs.outputDir,
|
||||||
json: inputs.json,
|
json: inputs.json,
|
||||||
shouldEscape: inputs.escapeJson
|
shouldEscape: inputs.escapeJson,
|
||||||
|
safeOutput: inputs.safeOutput
|
||||||
});
|
});
|
||||||
yield (0, utils_1.setOutput)({
|
yield (0, utils_1.setOutput)({
|
||||||
key: (0, utils_1.getOutputKey)('copied_files_count', outputPrefix),
|
key: (0, utils_1.getOutputKey)('copied_files_count', outputPrefix),
|
||||||
@ -494,7 +496,8 @@ const setOutputsAndGetModifiedAndChangedFilesStatus = ({ allDiffFiles, allFilter
|
|||||||
writeOutputFiles: inputs.writeOutputFiles,
|
writeOutputFiles: inputs.writeOutputFiles,
|
||||||
outputDir: inputs.outputDir,
|
outputDir: inputs.outputDir,
|
||||||
json: inputs.json,
|
json: inputs.json,
|
||||||
shouldEscape: inputs.escapeJson
|
shouldEscape: inputs.escapeJson,
|
||||||
|
safeOutput: inputs.safeOutput
|
||||||
});
|
});
|
||||||
yield (0, utils_1.setOutput)({
|
yield (0, utils_1.setOutput)({
|
||||||
key: (0, utils_1.getOutputKey)('modified_files_count', outputPrefix),
|
key: (0, utils_1.getOutputKey)('modified_files_count', outputPrefix),
|
||||||
@ -514,7 +517,8 @@ const setOutputsAndGetModifiedAndChangedFilesStatus = ({ allDiffFiles, allFilter
|
|||||||
writeOutputFiles: inputs.writeOutputFiles,
|
writeOutputFiles: inputs.writeOutputFiles,
|
||||||
outputDir: inputs.outputDir,
|
outputDir: inputs.outputDir,
|
||||||
json: inputs.json,
|
json: inputs.json,
|
||||||
shouldEscape: inputs.escapeJson
|
shouldEscape: inputs.escapeJson,
|
||||||
|
safeOutput: inputs.safeOutput
|
||||||
});
|
});
|
||||||
yield (0, utils_1.setOutput)({
|
yield (0, utils_1.setOutput)({
|
||||||
key: (0, utils_1.getOutputKey)('renamed_files_count', outputPrefix),
|
key: (0, utils_1.getOutputKey)('renamed_files_count', outputPrefix),
|
||||||
@ -534,7 +538,8 @@ const setOutputsAndGetModifiedAndChangedFilesStatus = ({ allDiffFiles, allFilter
|
|||||||
writeOutputFiles: inputs.writeOutputFiles,
|
writeOutputFiles: inputs.writeOutputFiles,
|
||||||
outputDir: inputs.outputDir,
|
outputDir: inputs.outputDir,
|
||||||
json: inputs.json,
|
json: inputs.json,
|
||||||
shouldEscape: inputs.escapeJson
|
shouldEscape: inputs.escapeJson,
|
||||||
|
safeOutput: inputs.safeOutput
|
||||||
});
|
});
|
||||||
yield (0, utils_1.setOutput)({
|
yield (0, utils_1.setOutput)({
|
||||||
key: (0, utils_1.getOutputKey)('type_changed_files_count', outputPrefix),
|
key: (0, utils_1.getOutputKey)('type_changed_files_count', outputPrefix),
|
||||||
@ -554,7 +559,8 @@ const setOutputsAndGetModifiedAndChangedFilesStatus = ({ allDiffFiles, allFilter
|
|||||||
writeOutputFiles: inputs.writeOutputFiles,
|
writeOutputFiles: inputs.writeOutputFiles,
|
||||||
outputDir: inputs.outputDir,
|
outputDir: inputs.outputDir,
|
||||||
json: inputs.json,
|
json: inputs.json,
|
||||||
shouldEscape: inputs.escapeJson
|
shouldEscape: inputs.escapeJson,
|
||||||
|
safeOutput: inputs.safeOutput
|
||||||
});
|
});
|
||||||
yield (0, utils_1.setOutput)({
|
yield (0, utils_1.setOutput)({
|
||||||
key: (0, utils_1.getOutputKey)('unmerged_files_count', outputPrefix),
|
key: (0, utils_1.getOutputKey)('unmerged_files_count', outputPrefix),
|
||||||
@ -574,7 +580,8 @@ const setOutputsAndGetModifiedAndChangedFilesStatus = ({ allDiffFiles, allFilter
|
|||||||
writeOutputFiles: inputs.writeOutputFiles,
|
writeOutputFiles: inputs.writeOutputFiles,
|
||||||
outputDir: inputs.outputDir,
|
outputDir: inputs.outputDir,
|
||||||
json: inputs.json,
|
json: inputs.json,
|
||||||
shouldEscape: inputs.escapeJson
|
shouldEscape: inputs.escapeJson,
|
||||||
|
safeOutput: inputs.safeOutput
|
||||||
});
|
});
|
||||||
yield (0, utils_1.setOutput)({
|
yield (0, utils_1.setOutput)({
|
||||||
key: (0, utils_1.getOutputKey)('unknown_files_count', outputPrefix),
|
key: (0, utils_1.getOutputKey)('unknown_files_count', outputPrefix),
|
||||||
@ -593,7 +600,8 @@ const setOutputsAndGetModifiedAndChangedFilesStatus = ({ allDiffFiles, allFilter
|
|||||||
writeOutputFiles: inputs.writeOutputFiles,
|
writeOutputFiles: inputs.writeOutputFiles,
|
||||||
outputDir: inputs.outputDir,
|
outputDir: inputs.outputDir,
|
||||||
json: inputs.json,
|
json: inputs.json,
|
||||||
shouldEscape: inputs.escapeJson
|
shouldEscape: inputs.escapeJson,
|
||||||
|
safeOutput: inputs.safeOutput
|
||||||
});
|
});
|
||||||
yield (0, utils_1.setOutput)({
|
yield (0, utils_1.setOutput)({
|
||||||
key: (0, utils_1.getOutputKey)('all_changed_and_modified_files_count', outputPrefix),
|
key: (0, utils_1.getOutputKey)('all_changed_and_modified_files_count', outputPrefix),
|
||||||
@ -618,7 +626,8 @@ const setOutputsAndGetModifiedAndChangedFilesStatus = ({ allDiffFiles, allFilter
|
|||||||
writeOutputFiles: inputs.writeOutputFiles,
|
writeOutputFiles: inputs.writeOutputFiles,
|
||||||
outputDir: inputs.outputDir,
|
outputDir: inputs.outputDir,
|
||||||
json: inputs.json,
|
json: inputs.json,
|
||||||
shouldEscape: inputs.escapeJson
|
shouldEscape: inputs.escapeJson,
|
||||||
|
safeOutput: inputs.safeOutput
|
||||||
});
|
});
|
||||||
yield (0, utils_1.setOutput)({
|
yield (0, utils_1.setOutput)({
|
||||||
key: (0, utils_1.getOutputKey)('all_changed_files_count', outputPrefix),
|
key: (0, utils_1.getOutputKey)('all_changed_files_count', outputPrefix),
|
||||||
@ -687,7 +696,8 @@ const setOutputsAndGetModifiedAndChangedFilesStatus = ({ allDiffFiles, allFilter
|
|||||||
writeOutputFiles: inputs.writeOutputFiles,
|
writeOutputFiles: inputs.writeOutputFiles,
|
||||||
outputDir: inputs.outputDir,
|
outputDir: inputs.outputDir,
|
||||||
json: inputs.json,
|
json: inputs.json,
|
||||||
shouldEscape: inputs.escapeJson
|
shouldEscape: inputs.escapeJson,
|
||||||
|
safeOutput: inputs.safeOutput
|
||||||
});
|
});
|
||||||
yield (0, utils_1.setOutput)({
|
yield (0, utils_1.setOutput)({
|
||||||
key: (0, utils_1.getOutputKey)('all_modified_files_count', outputPrefix),
|
key: (0, utils_1.getOutputKey)('all_modified_files_count', outputPrefix),
|
||||||
@ -768,7 +778,8 @@ const setOutputsAndGetModifiedAndChangedFilesStatus = ({ allDiffFiles, allFilter
|
|||||||
writeOutputFiles: inputs.writeOutputFiles,
|
writeOutputFiles: inputs.writeOutputFiles,
|
||||||
outputDir: inputs.outputDir,
|
outputDir: inputs.outputDir,
|
||||||
json: inputs.json,
|
json: inputs.json,
|
||||||
shouldEscape: inputs.escapeJson
|
shouldEscape: inputs.escapeJson,
|
||||||
|
safeOutput: inputs.safeOutput
|
||||||
});
|
});
|
||||||
yield (0, utils_1.setOutput)({
|
yield (0, utils_1.setOutput)({
|
||||||
key: (0, utils_1.getOutputKey)('deleted_files_count', outputPrefix),
|
key: (0, utils_1.getOutputKey)('deleted_files_count', outputPrefix),
|
||||||
@ -1498,6 +1509,7 @@ const getInputs = () => {
|
|||||||
});
|
});
|
||||||
const json = core.getBooleanInput('json', { required: false });
|
const json = core.getBooleanInput('json', { required: false });
|
||||||
const escapeJson = core.getBooleanInput('escape_json', { required: false });
|
const escapeJson = core.getBooleanInput('escape_json', { required: false });
|
||||||
|
const safeOutput = core.getBooleanInput('safe_output', { required: false });
|
||||||
const fetchDepth = core.getInput('fetch_depth', { required: false });
|
const fetchDepth = core.getInput('fetch_depth', { required: false });
|
||||||
const sinceLastRemoteCommit = core.getBooleanInput('since_last_remote_commit', { required: false });
|
const sinceLastRemoteCommit = core.getBooleanInput('since_last_remote_commit', { required: false });
|
||||||
const writeOutputFiles = core.getBooleanInput('write_output_files', {
|
const writeOutputFiles = core.getBooleanInput('write_output_files', {
|
||||||
@ -1587,6 +1599,7 @@ const getInputs = () => {
|
|||||||
dirNamesIncludeFilesSeparator,
|
dirNamesIncludeFilesSeparator,
|
||||||
json,
|
json,
|
||||||
escapeJson,
|
escapeJson,
|
||||||
|
safeOutput,
|
||||||
writeOutputFiles,
|
writeOutputFiles,
|
||||||
outputDir,
|
outputDir,
|
||||||
outputRenamedFilesAsDeletedAndAdded,
|
outputRenamedFilesAsDeletedAndAdded,
|
||||||
@ -1752,7 +1765,8 @@ const getChangedFilesFromLocalGitHistory = ({ inputs, env, workingDirectory, fil
|
|||||||
value: allOldNewRenamedFiles.paths,
|
value: allOldNewRenamedFiles.paths,
|
||||||
writeOutputFiles: inputs.writeOutputFiles,
|
writeOutputFiles: inputs.writeOutputFiles,
|
||||||
outputDir: inputs.outputDir,
|
outputDir: inputs.outputDir,
|
||||||
json: inputs.json
|
json: inputs.json,
|
||||||
|
safeOutput: inputs.safeOutput
|
||||||
});
|
});
|
||||||
yield (0, utils_1.setOutput)({
|
yield (0, utils_1.setOutput)({
|
||||||
key: 'all_old_new_renamed_files_count',
|
key: 'all_old_new_renamed_files_count',
|
||||||
@ -2800,11 +2814,12 @@ const setArrayOutput = ({ key, inputs, value, outputPrefix }) => __awaiter(void
|
|||||||
writeOutputFiles: inputs.writeOutputFiles,
|
writeOutputFiles: inputs.writeOutputFiles,
|
||||||
outputDir: inputs.outputDir,
|
outputDir: inputs.outputDir,
|
||||||
json: inputs.json,
|
json: inputs.json,
|
||||||
shouldEscape: inputs.escapeJson
|
shouldEscape: inputs.escapeJson,
|
||||||
|
safeOutput: inputs.safeOutput
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
exports.setArrayOutput = setArrayOutput;
|
exports.setArrayOutput = setArrayOutput;
|
||||||
const setOutput = ({ key, value, writeOutputFiles, outputDir, json = false, shouldEscape = false }) => __awaiter(void 0, void 0, void 0, function* () {
|
const setOutput = ({ key, value, writeOutputFiles, outputDir, json = false, shouldEscape = false, safeOutput = false }) => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
let cleanedValue;
|
let cleanedValue;
|
||||||
if (json) {
|
if (json) {
|
||||||
cleanedValue = (0, exports.jsonOutput)({ value, shouldEscape });
|
cleanedValue = (0, exports.jsonOutput)({ value, shouldEscape });
|
||||||
@ -2812,6 +2827,10 @@ const setOutput = ({ key, value, writeOutputFiles, outputDir, json = false, shou
|
|||||||
else {
|
else {
|
||||||
cleanedValue = value.toString().trim();
|
cleanedValue = value.toString().trim();
|
||||||
}
|
}
|
||||||
|
// if safeOutput is true, escape special characters for bash shell
|
||||||
|
if (safeOutput) {
|
||||||
|
cleanedValue = cleanedValue.replace(/[^\x20-\x7E]|[:*?"<>|;`$()&!]/g, '\\$&');
|
||||||
|
}
|
||||||
core.setOutput(key, cleanedValue);
|
core.setOutput(key, cleanedValue);
|
||||||
if (writeOutputFiles) {
|
if (writeOutputFiles) {
|
||||||
const extension = json ? 'json' : 'txt';
|
const extension = json ? 'json' : 'txt';
|
||||||
|
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
@ -1355,7 +1355,10 @@ export const setOutput = async ({
|
|||||||
|
|
||||||
// if safeOutput is true, escape special characters for bash shell
|
// if safeOutput is true, escape special characters for bash shell
|
||||||
if (safeOutput) {
|
if (safeOutput) {
|
||||||
cleanedValue = cleanedValue.replace(/[$()`|&;]/g, '\\$&')
|
cleanedValue = cleanedValue.replace(
|
||||||
|
/[^\x20-\x7E]|[:*?"<>|;`$()&!]/g,
|
||||||
|
'\\$&'
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
core.setOutput(key, cleanedValue)
|
core.setOutput(key, cleanedValue)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user