diff options
| author | robfram | 2018-03-13 19:36:36 +0100 |
|---|---|---|
| committer | Hein-Pieter van Braam | 2018-04-28 17:07:20 +0200 |
| commit | fa831f022436a8439d3a0198b3e689bef3573ebb (patch) | |
| tree | 8d39fad63853af16cb44b8d1a0875028ad8e4382 /editor/project_settings_editor.cpp | |
| parent | 141e389c3f80dcb71bbf86c67b9d2ea83652fa0c (diff) | |
| download | godot-fa831f022436a8439d3a0198b3e689bef3573ebb.tar.gz godot-fa831f022436a8439d3a0198b3e689bef3573ebb.tar.zst godot-fa831f022436a8439d3a0198b3e689bef3573ebb.zip | |
Fix non-valid characters for `input_action`
Add a new function to check action names, `_validate_action_name`, in
the spirit of `_valprop`. Offending characters include non-printable
ascii, and `\/=:"`. Also set only one text for the UI message.
(cherry picked from commit da6c07698f591b3eac773770dc776bf095c3d9ef)
Diffstat (limited to 'editor/project_settings_editor.cpp')
| -rw-r--r-- | editor/project_settings_editor.cpp | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/editor/project_settings_editor.cpp b/editor/project_settings_editor.cpp index 096d9c1a9..b24e8fd9f 100644 --- a/editor/project_settings_editor.cpp +++ b/editor/project_settings_editor.cpp @@ -115,6 +115,15 @@ void ProjectSettingsEditor::_notification(int p_what) { } } +static bool _validate_action_name(const String &p_name) { + const CharType *cstr = p_name.c_str(); + for (int i = 0; cstr[i]; i++) + if (cstr[i] == '/' || cstr[i] == ':' || cstr[i] == '"' || + cstr[i] == '=' || cstr[i] == '\\' || cstr[i] < 32) + return false; + return true; +} + void ProjectSettingsEditor::_action_selected() { TreeItem *ti = input_editor->get_selected(); @@ -137,12 +146,12 @@ void ProjectSettingsEditor::_action_edited() { if (new_name == old_name) return; - if (new_name.find("/") != -1 || new_name.find(":") != -1 || new_name.find("\"") != -1 || new_name == "") { + if (new_name == "" || !_validate_action_name(new_name)) { ti->set_text(0, old_name); add_at = "input/" + old_name; - message->set_text(TTR("Invalid action (anything goes but '/', ':' or '\"').")); + message->set_text(TTR("Invalid action name. it cannot be empty nor contain '/', ':', '=', '\\' or '\"'")); message->popup_centered(Size2(300, 100) * EDSCALE); return; } @@ -830,9 +839,9 @@ void ProjectSettingsEditor::_action_check(String p_action) { action_add->set_disabled(true); } else { - if (p_action.find("/") != -1 || p_action.find(":") != -1 || p_action.find("\"") != -1) { + if (!_validate_action_name(p_action)) { - action_add_error->set_text(TTR("Can't contain '/', ':' or '\"'")); + action_add_error->set_text(TTR("Invalid action name. it cannot be empty nor contain '/', ':', '=', '\\' or '\"'")); action_add_error->show(); action_add->set_disabled(true); return; |
