Skip to content

Commit

Permalink
Merge pull request #88071 from Calinou/gdscript-nodepath-autocomplete…
Browse files Browse the repository at this point in the history
…-fix-identifiers

Fix NodePath autocompletion to ensure paths are quoted when required
  • Loading branch information
akien-mga committed Feb 8, 2024
2 parents af645c4 + 1238b60 commit 50491db
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions modules/gdscript/gdscript_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3328,9 +3328,17 @@ ::Error GDScriptLanguage::complete_code(const String &p_code, const String &p_pa
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.
Expand Down

0 comments on commit 50491db

Please sign in to comment.