diff options
author | Hugo Locurcio <hugo.locurcio@hugo.pro> | 2024-02-07 18:50:58 +0100 |
---|---|---|
committer | Hugo Locurcio <hugo.locurcio@hugo.pro> | 2024-02-07 19:26:55 +0100 |
commit | 1238b60b22194072dddf7b31cce007426837b35c (patch) | |
tree | 425b10fb67de0da8321c0b1f62c1a39c77098dc7 | |
parent | 36e943b6b20cb7a8a89bc30489c4a81c3e149d74 (diff) | |
download | redot-engine-1238b60b22194072dddf7b31cce007426837b35c.tar.gz |
Fix NodePath autocompletion to ensure paths are quoted when required
Every component of the path is now checked to be a valid identifier,
so that node names that start with a digit always require the full
path to be quoted.
-rw-r--r-- | modules/gdscript/gdscript_editor.cpp | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/modules/gdscript/gdscript_editor.cpp b/modules/gdscript/gdscript_editor.cpp index 44e104da05..6c2079196a 100644 --- a/modules/gdscript/gdscript_editor.cpp +++ b/modules/gdscript/gdscript_editor.cpp @@ -3303,9 +3303,17 @@ static void _find_call_arguments(GDScriptParser::CompletionContext &p_context, c opt = opt.substr(1); } - // The path needs quotes if it's not a valid identifier (with an exception - // for "/" as path separator, which also doesn't require quotes). - if (!opt.replace("/", "_").is_valid_identifier()) { + // The path needs quotes if at least one of its components (excluding `/` separations) + // is not a valid identifier. + bool path_needs_quote = false; + for (const String &part : opt.split("/")) { + if (!part.is_valid_identifier()) { + path_needs_quote = true; + break; + } + } + + if (path_needs_quote) { // Ignore quote_style and just use double quotes for paths with apostrophes. // Double quotes don't need to be checked because they're not valid in node and property names. opt = opt.quote(opt.contains("'") ? "\"" : quote_style); // Handle user preference. |