diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2020-12-27 21:40:30 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-27 21:40:30 +0100 |
commit | 4425f7c2c1f3c168edcacfb4e3f1599c2dad10ed (patch) | |
tree | 5b5aadb66ac7f835cab9eabf09f8bdc4f298980f /modules/mono | |
parent | 8e49ccf658a192d94a6e674bdae75c9c0c249492 (diff) | |
parent | be1c161b0bff391083e7ae5514dbbaaae5c6b604 (diff) |
Merge pull request #44515 from eddsanity/master
Fixed #42149: bug where the default C# script template would sometimes produce an invalid class name
Diffstat (limited to 'modules/mono')
-rw-r--r-- | modules/mono/csharp_script.cpp | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/modules/mono/csharp_script.cpp b/modules/mono/csharp_script.cpp index 63ac0956f4..136bde631e 100644 --- a/modules/mono/csharp_script.cpp +++ b/modules/mono/csharp_script.cpp @@ -346,14 +346,18 @@ Ref<Script> CSharpLanguage::get_template(const String &p_class_name, const Strin "// }\n" "}\n"; - String base_class_name = get_base_class_name(p_base_class_name, p_class_name); + // Replaces all spaces in p_class_name with underscores to prevent + // erronous C# Script templates from being generated when the object name + // has spaces in it. + String class_name_no_spaces = p_class_name.replace(" ", "_"); + String base_class_name = get_base_class_name(p_base_class_name, class_name_no_spaces); script_template = script_template.replace("%BASE%", base_class_name) - .replace("%CLASS%", p_class_name); + .replace("%CLASS%", class_name_no_spaces); Ref<CSharpScript> script; script.instance(); script->set_source_code(script_template); - script->set_name(p_class_name); + script->set_name(class_name_no_spaces); return script; } @@ -364,9 +368,10 @@ bool CSharpLanguage::is_using_templates() { void CSharpLanguage::make_template(const String &p_class_name, const String &p_base_class_name, Ref<Script> &p_script) { String src = p_script->get_source_code(); - String base_class_name = get_base_class_name(p_base_class_name, p_class_name); + String class_name_no_spaces = p_class_name.replace(" ", "_"); + String base_class_name = get_base_class_name(p_base_class_name, class_name_no_spaces); src = src.replace("%BASE%", base_class_name) - .replace("%CLASS%", p_class_name) + .replace("%CLASS%", class_name_no_spaces) .replace("%TS%", _get_indentation()); p_script->set_source_code(src); } |