1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-10 13:00:37 +00:00

Merge pull request #68450 from KoBeWi/bracket_escapist

Allow to escape closing brackets in CFG tags
This commit is contained in:
Rémi Verschelde
2023-01-12 21:53:15 +01:00
committed by GitHub
3 changed files with 22 additions and 5 deletions

View File

@@ -208,7 +208,7 @@ Error ConfigFile::_internal_save(Ref<FileAccess> file) {
file->store_string("\n"); file->store_string("\n");
} }
if (!E.key.is_empty()) { if (!E.key.is_empty()) {
file->store_string("[" + E.key + "]\n\n"); file->store_string("[" + E.key.replace("]", "\\]") + "]\n\n");
} }
for (const KeyValue<String, Variant> &F : E.value) { for (const KeyValue<String, Variant> &F : E.value) {
@@ -308,7 +308,7 @@ Error ConfigFile::_parse(const String &p_path, VariantParser::Stream *p_stream)
if (!assign.is_empty()) { if (!assign.is_empty()) {
set_value(section, assign, value); set_value(section, assign, value);
} else if (!next_tag.name.is_empty()) { } else if (!next_tag.name.is_empty()) {
section = next_tag.name; section = next_tag.name.replace("\\]", "]");
} }
} }

View File

@@ -1358,6 +1358,7 @@ Error VariantParser::_parse_tag(Token &token, Stream *p_stream, int &line, Strin
if (p_simple_tag) { if (p_simple_tag) {
r_tag.name = ""; r_tag.name = "";
r_tag.fields.clear(); r_tag.fields.clear();
bool escaping = false;
if (p_stream->is_utf8()) { if (p_stream->is_utf8()) {
CharString cs; CharString cs;
@@ -1368,7 +1369,15 @@ Error VariantParser::_parse_tag(Token &token, Stream *p_stream, int &line, Strin
return ERR_PARSE_ERROR; return ERR_PARSE_ERROR;
} }
if (c == ']') { if (c == ']') {
break; if (escaping) {
escaping = false;
} else {
break;
}
} else if (c == '\\') {
escaping = true;
} else {
escaping = false;
} }
cs += c; cs += c;
} }
@@ -1381,7 +1390,15 @@ Error VariantParser::_parse_tag(Token &token, Stream *p_stream, int &line, Strin
return ERR_PARSE_ERROR; return ERR_PARSE_ERROR;
} }
if (c == ']') { if (c == ']') {
break; if (escaping) {
escaping = false;
} else {
break;
}
} else if (c == '\\') {
escaping = true;
} else {
escaping = false;
} }
r_tag.name += String::chr(c); r_tag.name += String::chr(c);
} }

View File

@@ -1273,7 +1273,7 @@ ProjectList::Item ProjectList::load_project_data(const String &p_path, bool p_fa
PackedStringArray unsupported_features = ProjectSettings::get_unsupported_features(project_features); PackedStringArray unsupported_features = ProjectSettings::get_unsupported_features(project_features);
uint64_t last_edited = 0; uint64_t last_edited = 0;
if (FileAccess::exists(conf)) { if (cf_err == OK) {
// The modification date marks the date the project was last edited. // The modification date marks the date the project was last edited.
// This is because the `project.godot` file will always be modified // This is because the `project.godot` file will always be modified
// when editing a project (but not when running it). // when editing a project (but not when running it).