Skip to content

Commit c2790ec

Browse files
authored
Merge pull request godotengine#68450 from KoBeWi/bracket_escapist
Allow to escape closing brackets in CFG tags
2 parents 886f7f8 + 0d122ce commit c2790ec

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

core/io/config_file.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ Error ConfigFile::_internal_save(Ref<FileAccess> file) {
208208
file->store_string("\n");
209209
}
210210
if (!E.key.is_empty()) {
211-
file->store_string("[" + E.key + "]\n\n");
211+
file->store_string("[" + E.key.replace("]", "\\]") + "]\n\n");
212212
}
213213

214214
for (const KeyValue<String, Variant> &F : E.value) {
@@ -308,7 +308,7 @@ Error ConfigFile::_parse(const String &p_path, VariantParser::Stream *p_stream)
308308
if (!assign.is_empty()) {
309309
set_value(section, assign, value);
310310
} else if (!next_tag.name.is_empty()) {
311-
section = next_tag.name;
311+
section = next_tag.name.replace("\\]", "]");
312312
}
313313
}
314314

core/variant/variant_parser.cpp

+19-2
Original file line numberDiff line numberDiff line change
@@ -1358,6 +1358,7 @@ Error VariantParser::_parse_tag(Token &token, Stream *p_stream, int &line, Strin
13581358
if (p_simple_tag) {
13591359
r_tag.name = "";
13601360
r_tag.fields.clear();
1361+
bool escaping = false;
13611362

13621363
if (p_stream->is_utf8()) {
13631364
CharString cs;
@@ -1368,7 +1369,15 @@ Error VariantParser::_parse_tag(Token &token, Stream *p_stream, int &line, Strin
13681369
return ERR_PARSE_ERROR;
13691370
}
13701371
if (c == ']') {
1371-
break;
1372+
if (escaping) {
1373+
escaping = false;
1374+
} else {
1375+
break;
1376+
}
1377+
} else if (c == '\\') {
1378+
escaping = true;
1379+
} else {
1380+
escaping = false;
13721381
}
13731382
cs += c;
13741383
}
@@ -1381,7 +1390,15 @@ Error VariantParser::_parse_tag(Token &token, Stream *p_stream, int &line, Strin
13811390
return ERR_PARSE_ERROR;
13821391
}
13831392
if (c == ']') {
1384-
break;
1393+
if (escaping) {
1394+
escaping = false;
1395+
} else {
1396+
break;
1397+
}
1398+
} else if (c == '\\') {
1399+
escaping = true;
1400+
} else {
1401+
escaping = false;
13851402
}
13861403
r_tag.name += String::chr(c);
13871404
}

editor/project_manager.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1273,7 +1273,7 @@ ProjectList::Item ProjectList::load_project_data(const String &p_path, bool p_fa
12731273
PackedStringArray unsupported_features = ProjectSettings::get_unsupported_features(project_features);
12741274

12751275
uint64_t last_edited = 0;
1276-
if (FileAccess::exists(conf)) {
1276+
if (cf_err == OK) {
12771277
// The modification date marks the date the project was last edited.
12781278
// This is because the `project.godot` file will always be modified
12791279
// when editing a project (but not when running it).

0 commit comments

Comments
 (0)