feat: sanitize file checks

This commit is contained in:
wancat committed 2023-10-29 17:41:38 +08:00
1 parent 50b1fe5124
commit 8f22babe7d
7 files changed
+115 -63

No files matched your search

+7 -7
View File
@@ -5,12 +5,12 @@ const fileTypes = {
socket: '-S',
}
function sanitizePath(path) {
return path.replace(/[^a-zA-Z0-9._/-]/g, '')
}
// eslint-disable-next-line import/prefer-default-export
export function buildFileCheckCmd(files) {
return files
.map(
({ path, type, exists }) =>
`${exists ? '' : '! '}test ${fileTypes[type] || '-e'} ${path}`
)
.join(' && ')
export function buildFileCheckCmd(file) {
const { path, type } = file
return ['test', fileTypes[type] || '-e', sanitizePath(path)]
}