From fb255a69b6d6b488116e83ef57308aa85b6ca53b Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Mon, 20 Jun 2016 18:41:59 -0300 Subject: [PATCH] Add quotes to .tscn keys, solves #4366 (cherry picked from commit 6872139300cefae120d6ec9493ebb134c41ec7cc) --- core/variant_parser.cpp | 15 ++++++++++++++- scene/resources/scene_format_text.cpp | 9 +++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/core/variant_parser.cpp b/core/variant_parser.cpp index 6d0f4eb8792..c44d902bf16 100644 --- a/core/variant_parser.cpp +++ b/core/variant_parser.cpp @@ -1747,7 +1747,20 @@ Error VariantParser::parse_tag_assign_eof(Stream *p_stream, int &line, String &r } if (c>32) { - if (c!='=') { + if (c=='"') { //quoted + p_stream->saved='"'; + Token tk; + Error err = get_token(p_stream,tk,line,r_err_str); + if (err) + return err; + if (tk.type!=TK_STRING) { + r_err_str="Error reading quoted string"; + return err; + } + + what=tk.value; + + } else if (c!='=') { what+=String::chr(c); } else { r_assign=what; diff --git a/scene/resources/scene_format_text.cpp b/scene/resources/scene_format_text.cpp index ba328c4aa42..08d12b1465d 100644 --- a/scene/resources/scene_format_text.cpp +++ b/scene/resources/scene_format_text.cpp @@ -1112,7 +1112,12 @@ void ResourceFormatSaverTextInstance::_find_resources(const Variant& p_variant,b } +static String _valprop(const String& p_name) { + if (p_name.find("\"")!=-1 || p_name.find("=")!=-1 || p_name.find(" ")!=-1) + return "\""+p_name.c_escape()+"\""; + return p_name; +} Error ResourceFormatSaverTextInstance::save(const String &p_path,const RES& p_resource,uint32_t p_flags) { @@ -1268,7 +1273,7 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path,const RES& p_re String vars; VariantWriter::write_to_string(value,vars,_write_resources,this); - f->store_string(name+" = "+vars+"\n"); + f->store_string(_valprop(name)+" = "+vars+"\n"); } @@ -1342,7 +1347,7 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path,const RES& p_re String vars; VariantWriter::write_to_string(state->get_node_property_value(i,j),vars,_write_resources,this); - f->store_string(String(state->get_node_property_name(i,j))+" = "+vars+"\n"); + f->store_string(_valprop(String(state->get_node_property_name(i,j)))+" = "+vars+"\n"); } if (state->get_node_property_count(i)) {