refactor: improve filename validation

This commit is contained in:
purocean
2024-06-19 01:29:03 +08:00
parent 6893b4061d
commit 774e59e229
4 changed files with 7 additions and 2 deletions
+4 -2
View File
@@ -41,8 +41,10 @@ function encrypt (content: any, password: string) {
}
function checkFilePath (path: string) {
if (path.includes('#')) {
throw new Error('Path should not contain #')
// check filename is valid
const filename = basename(path)
if (/[<>:"|?*#]/.test(filename)) {
throw new Error(t('document.invalid-filename', '< > : " / \\ | ? * #'))
}
}
+1
View File
@@ -177,6 +177,7 @@ const data = {
},
'document': {
'current-path': 'Current Path: %s',
'invalid-filename': 'File name cannot contain the following characters: %s',
'password-create': '[Create] Please enter a password',
'password-save': '[Save] Please enter password of the file',
'password-open': '[Open] Please enter password of the file',
+1
View File
@@ -178,6 +178,7 @@ const data: BaseLanguage = {
},
'document': {
'current-path': '当前路径: %s',
'invalid-filename': '文件名不能包含以下字符: %s',
'password-create': '[创建] 请输入密码',
'password-save': '[保存] 请输入密码',
'password-open': '[打开] 请输入密码',
+1
View File
@@ -178,6 +178,7 @@ const data: BaseLanguage = {
},
'document': {
'current-path': '當前路徑: %s',
'invalid-filename': '檔案名不能包含以下字符: %s',
'password-create': '[創建] 請輸入密碼',
'password-save': '[保存] 請輸入密碼',
'password-open': '[打開] 請輸入密碼',