mirror of
https://github.com/tj-actions/changed-files
synced 2025-03-05 11:06:22 +00:00
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
4 changed files with 44 additions and 16 deletions
|
@ -572,6 +572,12 @@ Support this project with a :star:
|
|||
# Default: "\n"
|
||||
recover_files_separator: ''
|
||||
|
||||
# Apply sanitization to output filenames before being set as
|
||||
# output.
|
||||
# Type: boolean
|
||||
# Default: "true"
|
||||
safe_output: ''
|
||||
|
||||
# Split character for output strings.
|
||||
# Type: string
|
||||
# Default: " "
|
||||
|
|
47
dist/index.js
generated
vendored
47
dist/index.js
generated
vendored
|
@ -454,7 +454,8 @@ const setOutputsAndGetModifiedAndChangedFilesStatus = ({ allDiffFiles, allFilter
|
|||
writeOutputFiles: inputs.writeOutputFiles,
|
||||
outputDir: inputs.outputDir,
|
||||
json: inputs.json,
|
||||
shouldEscape: inputs.escapeJson
|
||||
shouldEscape: inputs.escapeJson,
|
||||
safeOutput: inputs.safeOutput
|
||||
});
|
||||
yield (0, utils_1.setOutput)({
|
||||
key: (0, utils_1.getOutputKey)('added_files_count', outputPrefix),
|
||||
|
@ -474,7 +475,8 @@ const setOutputsAndGetModifiedAndChangedFilesStatus = ({ allDiffFiles, allFilter
|
|||
writeOutputFiles: inputs.writeOutputFiles,
|
||||
outputDir: inputs.outputDir,
|
||||
json: inputs.json,
|
||||
shouldEscape: inputs.escapeJson
|
||||
shouldEscape: inputs.escapeJson,
|
||||
safeOutput: inputs.safeOutput
|
||||
});
|
||||
yield (0, utils_1.setOutput)({
|
||||
key: (0, utils_1.getOutputKey)('copied_files_count', outputPrefix),
|
||||
|
@ -494,7 +496,8 @@ const setOutputsAndGetModifiedAndChangedFilesStatus = ({ allDiffFiles, allFilter
|
|||
writeOutputFiles: inputs.writeOutputFiles,
|
||||
outputDir: inputs.outputDir,
|
||||
json: inputs.json,
|
||||
shouldEscape: inputs.escapeJson
|
||||
shouldEscape: inputs.escapeJson,
|
||||
safeOutput: inputs.safeOutput
|
||||
});
|
||||
yield (0, utils_1.setOutput)({
|
||||
key: (0, utils_1.getOutputKey)('modified_files_count', outputPrefix),
|
||||
|
@ -514,7 +517,8 @@ const setOutputsAndGetModifiedAndChangedFilesStatus = ({ allDiffFiles, allFilter
|
|||
writeOutputFiles: inputs.writeOutputFiles,
|
||||
outputDir: inputs.outputDir,
|
||||
json: inputs.json,
|
||||
shouldEscape: inputs.escapeJson
|
||||
shouldEscape: inputs.escapeJson,
|
||||
safeOutput: inputs.safeOutput
|
||||
});
|
||||
yield (0, utils_1.setOutput)({
|
||||
key: (0, utils_1.getOutputKey)('renamed_files_count', outputPrefix),
|
||||
|
@ -534,7 +538,8 @@ const setOutputsAndGetModifiedAndChangedFilesStatus = ({ allDiffFiles, allFilter
|
|||
writeOutputFiles: inputs.writeOutputFiles,
|
||||
outputDir: inputs.outputDir,
|
||||
json: inputs.json,
|
||||
shouldEscape: inputs.escapeJson
|
||||
shouldEscape: inputs.escapeJson,
|
||||
safeOutput: inputs.safeOutput
|
||||
});
|
||||
yield (0, utils_1.setOutput)({
|
||||
key: (0, utils_1.getOutputKey)('type_changed_files_count', outputPrefix),
|
||||
|
@ -554,7 +559,8 @@ const setOutputsAndGetModifiedAndChangedFilesStatus = ({ allDiffFiles, allFilter
|
|||
writeOutputFiles: inputs.writeOutputFiles,
|
||||
outputDir: inputs.outputDir,
|
||||
json: inputs.json,
|
||||
shouldEscape: inputs.escapeJson
|
||||
shouldEscape: inputs.escapeJson,
|
||||
safeOutput: inputs.safeOutput
|
||||
});
|
||||
yield (0, utils_1.setOutput)({
|
||||
key: (0, utils_1.getOutputKey)('unmerged_files_count', outputPrefix),
|
||||
|
@ -574,7 +580,8 @@ const setOutputsAndGetModifiedAndChangedFilesStatus = ({ allDiffFiles, allFilter
|
|||
writeOutputFiles: inputs.writeOutputFiles,
|
||||
outputDir: inputs.outputDir,
|
||||
json: inputs.json,
|
||||
shouldEscape: inputs.escapeJson
|
||||
shouldEscape: inputs.escapeJson,
|
||||
safeOutput: inputs.safeOutput
|
||||
});
|
||||
yield (0, utils_1.setOutput)({
|
||||
key: (0, utils_1.getOutputKey)('unknown_files_count', outputPrefix),
|
||||
|
@ -593,7 +600,8 @@ const setOutputsAndGetModifiedAndChangedFilesStatus = ({ allDiffFiles, allFilter
|
|||
writeOutputFiles: inputs.writeOutputFiles,
|
||||
outputDir: inputs.outputDir,
|
||||
json: inputs.json,
|
||||
shouldEscape: inputs.escapeJson
|
||||
shouldEscape: inputs.escapeJson,
|
||||
safeOutput: inputs.safeOutput
|
||||
});
|
||||
yield (0, utils_1.setOutput)({
|
||||
key: (0, utils_1.getOutputKey)('all_changed_and_modified_files_count', outputPrefix),
|
||||
|
@ -618,7 +626,8 @@ const setOutputsAndGetModifiedAndChangedFilesStatus = ({ allDiffFiles, allFilter
|
|||
writeOutputFiles: inputs.writeOutputFiles,
|
||||
outputDir: inputs.outputDir,
|
||||
json: inputs.json,
|
||||
shouldEscape: inputs.escapeJson
|
||||
shouldEscape: inputs.escapeJson,
|
||||
safeOutput: inputs.safeOutput
|
||||
});
|
||||
yield (0, utils_1.setOutput)({
|
||||
key: (0, utils_1.getOutputKey)('all_changed_files_count', outputPrefix),
|
||||
|
@ -687,7 +696,8 @@ const setOutputsAndGetModifiedAndChangedFilesStatus = ({ allDiffFiles, allFilter
|
|||
writeOutputFiles: inputs.writeOutputFiles,
|
||||
outputDir: inputs.outputDir,
|
||||
json: inputs.json,
|
||||
shouldEscape: inputs.escapeJson
|
||||
shouldEscape: inputs.escapeJson,
|
||||
safeOutput: inputs.safeOutput
|
||||
});
|
||||
yield (0, utils_1.setOutput)({
|
||||
key: (0, utils_1.getOutputKey)('all_modified_files_count', outputPrefix),
|
||||
|
@ -768,7 +778,8 @@ const setOutputsAndGetModifiedAndChangedFilesStatus = ({ allDiffFiles, allFilter
|
|||
writeOutputFiles: inputs.writeOutputFiles,
|
||||
outputDir: inputs.outputDir,
|
||||
json: inputs.json,
|
||||
shouldEscape: inputs.escapeJson
|
||||
shouldEscape: inputs.escapeJson,
|
||||
safeOutput: inputs.safeOutput
|
||||
});
|
||||
yield (0, utils_1.setOutput)({
|
||||
key: (0, utils_1.getOutputKey)('deleted_files_count', outputPrefix),
|
||||
|
@ -1498,6 +1509,7 @@ const getInputs = () => {
|
|||
});
|
||||
const json = core.getBooleanInput('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 sinceLastRemoteCommit = core.getBooleanInput('since_last_remote_commit', { required: false });
|
||||
const writeOutputFiles = core.getBooleanInput('write_output_files', {
|
||||
|
@ -1587,6 +1599,7 @@ const getInputs = () => {
|
|||
dirNamesIncludeFilesSeparator,
|
||||
json,
|
||||
escapeJson,
|
||||
safeOutput,
|
||||
writeOutputFiles,
|
||||
outputDir,
|
||||
outputRenamedFilesAsDeletedAndAdded,
|
||||
|
@ -1752,7 +1765,8 @@ const getChangedFilesFromLocalGitHistory = ({ inputs, env, workingDirectory, fil
|
|||
value: allOldNewRenamedFiles.paths,
|
||||
writeOutputFiles: inputs.writeOutputFiles,
|
||||
outputDir: inputs.outputDir,
|
||||
json: inputs.json
|
||||
json: inputs.json,
|
||||
safeOutput: inputs.safeOutput
|
||||
});
|
||||
yield (0, utils_1.setOutput)({
|
||||
key: 'all_old_new_renamed_files_count',
|
||||
|
@ -2800,11 +2814,12 @@ const setArrayOutput = ({ key, inputs, value, outputPrefix }) => __awaiter(void
|
|||
writeOutputFiles: inputs.writeOutputFiles,
|
||||
outputDir: inputs.outputDir,
|
||||
json: inputs.json,
|
||||
shouldEscape: inputs.escapeJson
|
||||
shouldEscape: inputs.escapeJson,
|
||||
safeOutput: inputs.safeOutput
|
||||
});
|
||||
});
|
||||
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;
|
||||
if (json) {
|
||||
cleanedValue = (0, exports.jsonOutput)({ value, shouldEscape });
|
||||
|
@ -2812,6 +2827,10 @@ const setOutput = ({ key, value, writeOutputFiles, outputDir, json = false, shou
|
|||
else {
|
||||
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);
|
||||
if (writeOutputFiles) {
|
||||
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) {
|
||||
cleanedValue = cleanedValue.replace(/[$()`|&;]/g, '\\$&')
|
||||
cleanedValue = cleanedValue.replace(
|
||||
/[^\x20-\x7E]|[:*?"<>|;`$()&!]/g,
|
||||
'\\$&'
|
||||
)
|
||||
}
|
||||
|
||||
core.setOutput(key, cleanedValue)
|
||||
|
|
Loading…
Add table
Reference in a new issue