diff --git a/editor/directory_create_dialog.cpp b/editor/directory_create_dialog.cpp index 504f1105f..40f40f52b 100644 --- a/editor/directory_create_dialog.cpp +++ b/editor/directory_create_dialog.cpp @@ -52,15 +52,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 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."); } } diff --git a/editor/editor_dir_dialog.cpp b/editor/editor_dir_dialog.cpp index b3450c318..ea1792fca 100644 --- a/editor/editor_dir_dialog.cpp +++ b/editor/editor_dir_dialog.cpp @@ -164,7 +164,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); diff --git a/editor/editor_file_dialog.cpp b/editor/editor_file_dialog.cpp index 554f3137e..1586e51cb 100644 --- a/editor/editor_file_dialog.cpp +++ b/editor/editor_file_dialog.cpp @@ -1113,9 +1113,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(); diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index e2e94a2dc..a52fd2ace 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -1840,6 +1840,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(); ObjectID current = editor_history.get_current(); diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp index b45d0c4cb..db467cfea 100644 --- a/editor/filesystem_dock.cpp +++ b/editor/filesystem_dock.cpp @@ -1446,6 +1446,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 && old_name.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.")); @@ -1508,6 +1511,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(); diff --git a/editor/script_create_dialog.cpp b/editor/script_create_dialog.cpp index 2259e43e3..162d92079 100644 --- a/editor/script_create_dialog.cpp +++ b/editor/script_create_dialog.cpp @@ -193,6 +193,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://")) {