mirror of
https://github.com/usebruno/bruno.git
synced 2025-02-28 15:41:25 +01:00
feat: implement utility function isValidFilename
This commit is contained in:
parent
ec5c593de4
commit
79f6a844c8
@ -160,6 +160,20 @@ const sanitizeDirectoryName = (name) => {
|
|||||||
return name.replace(/[<>:"/\\|?*\x00-\x1F]+/g, '-');
|
return name.replace(/[<>:"/\\|?*\x00-\x1F]+/g, '-');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const isValidFilename = (fileName) => {
|
||||||
|
const inValidChars = /[\\/:*?"<>|]/;
|
||||||
|
|
||||||
|
if (!fileName || inValidChars.test(fileName)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fileName.endsWith(' ') || fileName.endsWith('.')) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
const safeToRename = (oldPath, newPath) => {
|
const safeToRename = (oldPath, newPath) => {
|
||||||
try {
|
try {
|
||||||
// If the new path doesn't exist, it's safe to rename
|
// If the new path doesn't exist, it's safe to rename
|
||||||
@ -204,5 +218,6 @@ module.exports = {
|
|||||||
searchForFiles,
|
searchForFiles,
|
||||||
searchForBruFiles,
|
searchForBruFiles,
|
||||||
sanitizeDirectoryName,
|
sanitizeDirectoryName,
|
||||||
safeToRename
|
safeToRename,
|
||||||
|
isValidFilename
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user