1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-23 12:27:48 +00:00

update-dir-file-path-validation (#6958)

* update-dir-file-path-validation

* Update utils.js
This commit is contained in:
Ranjiwei
2024-10-31 09:33:21 +08:00
committed by GitHub
parent 615163802b
commit 20fde74744
5 changed files with 56 additions and 10 deletions

View File

@@ -1636,3 +1636,34 @@ export const Utils = {
};
export const isMobile = (typeof (window) !== 'undefined') && (window.innerWidth < 768 || navigator.userAgent.toLowerCase().match(/(ipod|ipad|iphone|android|coolpad|mmp|smartphone|midp|wap|xoom|symbian|j2me|blackberry|wince)/i) != null);
export const validateName = (newName) => {
let isValid = true;
let errMessage = '';
if (!newName || !newName.trim()) {
isValid = false;
errMessage = gettext('Name is required');
return { isValid, errMessage };
}
if (newName.includes('/')) {
isValid = false;
errMessage = gettext('Name cannot contain slash');
return { isValid, errMessage };
}
if (newName.includes('`')) {
isValid = false;
errMessage = gettext('Name cannot contain backtick');
return { isValid, errMessage };
}
if (newName.includes('\\')) {
isValid = false;
errMessage = gettext('Name cannot contain backslash');
return { isValid, errMessage };
}
if (newName === '..') {
isValid = false;
errMessage = gettext('Name cannot be double dots');
return { isValid, errMessage };
}
return { isValid, errMessage };
};