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

Script editor wrongly replaces and quotes non-ASCII letters #92899

Closed
KoBeWi opened this issue Jun 8, 2024 · 1 comment · Fixed by #97323
Closed

Script editor wrongly replaces and quotes non-ASCII letters #92899

KoBeWi opened this issue Jun 8, 2024 · 1 comment · Fixed by #97323

Comments

@KoBeWi
Copy link
Member

KoBeWi commented Jun 8, 2024

Tested versions

4.3 beta1 and earlier

System information

Windows 10.0.19045 - Vulkan (Forward+) - dedicated NVIDIA GeForce GTX 1060 (NVIDIA; 31.0.15.4633) - Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz (8 Threads)

Issue description

godot_fAwuz6123l.mp4

The non-ASCII letters are replaced with _, while they make a valid identifier. Also the path is quoted, but it works without the quote.

Steps to reproduce

  1. Have a node with some accented letters in name, like bułka
  2. Drag and drop it to script editor while holding Ctrl
  3. The line ends up as @onready var bu_ka = $"bułka"
  4. Change it to @onready var bułka = $bułka
  5. It still works, so the identifier processing was unnecessary

Minimal reproduction project (MRP)

N/A

@dalexeev
Copy link
Member

dalexeev commented Jun 8, 2024

This is because validate_identifier() is used.

String variable_name = String(node->get_name()).to_snake_case().validate_identifier();
if (use_type) {
StringName class_name = node->get_class_name();
Ref<Script> node_script = node->get_script();
if (node_script.is_valid()) {
StringName global_node_script_name = node_script->get_global_name();
if (global_node_script_name != StringName()) {
class_name = global_node_script_name;
}
}
text_to_drop += vformat("@onready var %s: %s = %c%s\n", variable_name, class_name, is_unique ? '%' : '$', path);
} else {
text_to_drop += vformat("@onready var %s = %c%s\n", variable_name, is_unique ? '%' : '$', path);
}

godot/core/string/ustring.cpp

Lines 4469 to 4490 in 5833f59

String String::validate_identifier() const {
if (is_empty()) {
return "_"; // Empty string is not a valid identifier;
}
String result;
if (is_digit(operator[](0))) {
result = "_" + *this;
} else {
result = *this;
}
int len = result.length();
char32_t *buffer = result.ptrw();
for (int i = 0; i < len; i++) {
if (!is_ascii_identifier_char(buffer[i])) {
buffer[i] = '_';
}
}
return result;
}

@github-project-automation github-project-automation bot moved this to For team assessment in GDScript Issue Triage Jun 8, 2024
@dalexeev dalexeev moved this from For team assessment to Up for grabs in GDScript Issue Triage Aug 8, 2024
@akien-mga akien-mga added this to the 4.4 milestone Sep 23, 2024
@github-project-automation github-project-automation bot moved this from Up for grabs to Done in GDScript Issue Triage Sep 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants