mirror of
https://github.com/purocean/yn.git
synced 2026-09-24 15:46:02 +08:00
refactor: improve filename validation
This commit is contained in:
@@ -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', '< > : " / \\ | ? * #'))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -178,6 +178,7 @@ const data: BaseLanguage = {
|
||||
},
|
||||
'document': {
|
||||
'current-path': '当前路径: %s',
|
||||
'invalid-filename': '文件名不能包含以下字符: %s',
|
||||
'password-create': '[创建] 请输入密码',
|
||||
'password-save': '[保存] 请输入密码',
|
||||
'password-open': '[打开] 请输入密码',
|
||||
|
||||
@@ -178,6 +178,7 @@ const data: BaseLanguage = {
|
||||
},
|
||||
'document': {
|
||||
'current-path': '當前路徑: %s',
|
||||
'invalid-filename': '檔案名不能包含以下字符: %s',
|
||||
'password-create': '[創建] 請輸入密碼',
|
||||
'password-save': '[保存] 請輸入密碼',
|
||||
'password-open': '[打開] 請輸入密碼',
|
||||
|
||||
Reference in New Issue
Block a user