Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NodePath autocompletion to ensure paths are quoted when required #88071

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions modules/gdscript/gdscript_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3303,9 +3303,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
Loading