Prevent using name with leading dot when create/rename/duplicate scene/folder/script/resource
Fixes #62497
This commit is contained in:
parent
e22335ec72
commit
6782738a85
7 changed files with 47 additions and 6 deletions
|
@ -51,15 +51,22 @@ String DirectoryCreateDialog::_validate_path(const String &p_path) const {
|
|||
return TTR("Folder name cannot be empty.");
|
||||
}
|
||||
|
||||
if (p_path.find("\\") != -1 || p_path.find(":") != -1 || p_path.find("*") != -1 ||
|
||||
p_path.find("|") != -1 || p_path.find(">") != -1) {
|
||||
return TTR("Folder name contains invalid characters.");
|
||||
}
|
||||
|
||||
const Vector<String> parts = p_path.split("/");
|
||||
for (int i = 0; i < parts.size(); i++) {
|
||||
const String part = parts[i];
|
||||
if (part.empty()) {
|
||||
return TTR("Folder name cannot be empty.");
|
||||
}
|
||||
if (p_path.find("\\") != -1 || p_path.find(":") != -1 || p_path.find("*") != -1 ||
|
||||
p_path.find("|") != -1 || p_path.find(">") != -1 || p_path.ends_with(".") || p_path.ends_with(" ")) {
|
||||
return TTR("Folder name contains invalid characters.");
|
||||
if (part.ends_with(" ") || part[0] == ' ') {
|
||||
return TTR("Folder name cannot begin or end with a space.");
|
||||
}
|
||||
if (part[0] == '.') {
|
||||
return TTR("Folder name cannot begin with a dot.");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -150,7 +150,15 @@ void EditorDirDialog::_make_dir_confirm() {
|
|||
|
||||
DirAccessRef d = DirAccess::open(dir);
|
||||
ERR_FAIL_COND_MSG(!d, "Cannot open directory '" + dir + "'.");
|
||||
Error err = d->make_dir(makedirname->get_text());
|
||||
|
||||
String dir_name = makedirname->get_text();
|
||||
if (dir_name.begins_with(".")) {
|
||||
mkdirerr->set_text(TTR("Could not use a name with a leading dot."));
|
||||
mkdirerr->popup_centered_minsize(Size2(250, 80) * EDSCALE);
|
||||
return;
|
||||
}
|
||||
|
||||
Error err = d->make_dir(dir_name);
|
||||
|
||||
if (err != OK) {
|
||||
mkdirerr->popup_centered_minsize(Size2(250, 80) * EDSCALE);
|
||||
|
|
|
@ -1083,9 +1083,16 @@ EditorFileDialog::Access EditorFileDialog::get_access() const {
|
|||
}
|
||||
|
||||
void EditorFileDialog::_make_dir_confirm() {
|
||||
Error err = dir_access->make_dir(makedirname->get_text().strip_edges());
|
||||
String dir_name = makedirname->get_text().strip_edges();
|
||||
if (dir_name.begins_with(".")) {
|
||||
mkdirerr->set_text(TTR("Could not use a name with a leading dot."));
|
||||
mkdirerr->popup_centered_minsize(Size2(250, 50) * EDSCALE);
|
||||
return;
|
||||
}
|
||||
|
||||
Error err = dir_access->make_dir(dir_name);
|
||||
if (err == OK) {
|
||||
dir_access->change_dir(makedirname->get_text().strip_edges());
|
||||
dir_access->change_dir(dir_name);
|
||||
invalidate();
|
||||
update_filters();
|
||||
update_dir();
|
||||
|
|
|
@ -1797,6 +1797,11 @@ void EditorNode::_dialog_action(String p_file) {
|
|||
case RESOURCE_SAVE:
|
||||
case RESOURCE_SAVE_AS: {
|
||||
ERR_FAIL_COND(saving_resource.is_null());
|
||||
if (p_file.get_file().begins_with(".")) {
|
||||
show_accept(TTR("Could not use a name with a leading dot."), TTR("OK"));
|
||||
return;
|
||||
}
|
||||
|
||||
save_resource_in_path(saving_resource, p_file);
|
||||
saving_resource = Ref<Resource>();
|
||||
ObjectID current = editor_history.get_current();
|
||||
|
|
|
@ -1394,6 +1394,9 @@ void FileSystemDock::_rename_operation_confirm() {
|
|||
} else if (new_name.find("/") != -1 || new_name.find("\\") != -1 || new_name.find(":") != -1) {
|
||||
EditorNode::get_singleton()->show_warning(TTR("Name contains invalid characters."));
|
||||
return;
|
||||
} else if (new_name[0] == '.') {
|
||||
EditorNode::get_singleton()->show_warning(TTR("This filename begins with a dot rendering the file invisible to the editor.\nIf you want to rename it anyway, use your operating system's file manager."));
|
||||
return;
|
||||
} else if (to_rename.is_file && to_rename.path.get_extension() != new_name.get_extension()) {
|
||||
if (!EditorFileSystem::get_singleton()->get_valid_extensions().find(new_name.get_extension())) {
|
||||
EditorNode::get_singleton()->show_warning(TTR("This file extension is not recognized by the editor.\nIf you want to rename it anyway, use your operating system's file manager.\nAfter renaming to an unknown extension, the file won't be shown in the editor anymore."));
|
||||
|
@ -1456,6 +1459,9 @@ void FileSystemDock::_duplicate_operation_confirm() {
|
|||
} else if (new_name.find("/") != -1 || new_name.find("\\") != -1 || new_name.find(":") != -1) {
|
||||
EditorNode::get_singleton()->show_warning(TTR("Name contains invalid characters."));
|
||||
return;
|
||||
} else if (new_name[0] == '.') {
|
||||
EditorNode::get_singleton()->show_warning(TTR("Name begins with a dot."));
|
||||
return;
|
||||
}
|
||||
|
||||
String base_dir = to_duplicate.path.get_base_dir();
|
||||
|
|
|
@ -110,6 +110,11 @@ void SceneCreateDialog::update_dialog(Variant p_discard) {
|
|||
is_valid = false;
|
||||
}
|
||||
|
||||
if (is_valid && scene_name[0] == '.') {
|
||||
update_error(file_error_label, MSG_ERROR, TTR("File name begins with a dot."));
|
||||
is_valid = false;
|
||||
}
|
||||
|
||||
if (is_valid) {
|
||||
scene_name = directory.plus_file(scene_name);
|
||||
DirAccessRef da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
|
||||
|
|
|
@ -169,6 +169,9 @@ String ScriptCreateDialog::_validate_path(const String &p_path, bool p_file_must
|
|||
if (p.get_file().get_basename() == "") {
|
||||
return TTR("Filename is empty.");
|
||||
}
|
||||
if (p.get_file().begins_with(".")) {
|
||||
return TTR("Name begins with a dot.");
|
||||
}
|
||||
|
||||
p = ProjectSettings::get_singleton()->localize_path(p);
|
||||
if (!p.begins_with("res://")) {
|
||||
|
|
Loading…
Reference in a new issue