From 176afb2feb7ed235bf9d7528ee3e8af092f12f90 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Fri, 8 Jan 2016 19:00:45 -0300 Subject: [PATCH] -Use simpler methods for parsing simple tags, fixes #3274 --- core/io/config_file.cpp | 2 +- core/variant_parser.cpp | 33 ++++++++++++++++++++++++++++----- core/variant_parser.h | 6 +++--- 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/core/io/config_file.cpp b/core/io/config_file.cpp index a01e935baa7..d79a3d12881 100644 --- a/core/io/config_file.cpp +++ b/core/io/config_file.cpp @@ -177,7 +177,7 @@ Error ConfigFile::load(const String& p_path) { next_tag.fields.clear(); next_tag.name=String(); - err = VariantParser::parse_tag_assign_eof(&stream,lines,error_text,next_tag,assign,value,NULL); + err = VariantParser::parse_tag_assign_eof(&stream,lines,error_text,next_tag,assign,value,NULL,true); if (err==ERR_FILE_EOF) return OK; else if (err!=OK) { diff --git a/core/variant_parser.cpp b/core/variant_parser.cpp index 5ca09841031..e7fbbba548c 100644 --- a/core/variant_parser.cpp +++ b/core/variant_parser.cpp @@ -1580,7 +1580,7 @@ Error VariantParser::_parse_dictionary(Dictionary &object, Stream *p_stream, int } -Error VariantParser::_parse_tag(Token& token, Stream *p_stream, int &line, String &r_err_str, Tag& r_tag, ResourceParser *p_res_parser) { +Error VariantParser::_parse_tag(Token& token, Stream *p_stream, int &line, String &r_err_str, Tag& r_tag, ResourceParser *p_res_parser,bool p_simple_tag) { r_tag.fields.clear(); @@ -1590,6 +1590,29 @@ Error VariantParser::_parse_tag(Token& token, Stream *p_stream, int &line, Strin } + if (p_simple_tag) { + + r_tag.name=""; + r_tag.fields.clear(); + + while(true) { + + CharType c = p_stream->get_char(); + if (p_stream->is_eof()) { + r_err_str="Unexpected EOF while parsing simple tag"; + return ERR_PARSE_ERROR; + } + if (c==']') + break; + r_tag.name+=String::chr(c); + } + + r_tag.name = r_tag.name.strip_edges(); + + return OK; + + } + get_token(p_stream,token,line,r_err_str); @@ -1654,7 +1677,7 @@ Error VariantParser::_parse_tag(Token& token, Stream *p_stream, int &line, Strin } -Error VariantParser::parse_tag(Stream *p_stream, int &line, String &r_err_str, Tag& r_tag, ResourceParser *p_res_parser) { +Error VariantParser::parse_tag(Stream *p_stream, int &line, String &r_err_str, Tag& r_tag, ResourceParser *p_res_parser, bool p_simple_tag) { Token token; get_token(p_stream,token,line,r_err_str); @@ -1668,11 +1691,11 @@ Error VariantParser::parse_tag(Stream *p_stream, int &line, String &r_err_str, T return ERR_PARSE_ERROR; } - return _parse_tag(token,p_stream,line,r_err_str,r_tag,p_res_parser); + return _parse_tag(token,p_stream,line,r_err_str,r_tag,p_res_parser,p_simple_tag); } -Error VariantParser::parse_tag_assign_eof(Stream *p_stream, int &line, String &r_err_str, Tag& r_tag, String &r_assign, Variant &r_value, ResourceParser *p_res_parser) { +Error VariantParser::parse_tag_assign_eof(Stream *p_stream, int &line, String &r_err_str, Tag& r_tag, String &r_assign, Variant &r_value, ResourceParser *p_res_parser, bool p_simple_tag) { //assign.. @@ -1710,7 +1733,7 @@ Error VariantParser::parse_tag_assign_eof(Stream *p_stream, int &line, String &r //it's a tag! p_stream->saved='['; //go back one - Error err = parse_tag(p_stream,line,r_err_str,r_tag,p_res_parser); + Error err = parse_tag(p_stream,line,r_err_str,r_tag,p_res_parser,p_simple_tag); return err; } diff --git a/core/variant_parser.h b/core/variant_parser.h index 09122715374..00f6910b29e 100644 --- a/core/variant_parser.h +++ b/core/variant_parser.h @@ -104,12 +104,12 @@ private: static Error _parse_enginecfg(Stream *p_stream, Vector& strings, int &line, String &r_err_str); static Error _parse_dictionary(Dictionary &object, Stream *p_stream, int &line, String &r_err_str,ResourceParser *p_res_parser=NULL); static Error _parse_array(Array &array, Stream *p_stream, int &line, String &r_err_str,ResourceParser *p_res_parser=NULL); - static Error _parse_tag(Token& token,Stream *p_stream, int &line, String &r_err_str,Tag& r_tag,ResourceParser *p_res_parser=NULL); + static Error _parse_tag(Token& token,Stream *p_stream, int &line, String &r_err_str,Tag& r_tag,ResourceParser *p_res_parser=NULL,bool p_simple_tag=false); public: - static Error parse_tag(Stream *p_stream, int &line, String &r_err_str,Tag& r_tag,ResourceParser *p_res_parser=NULL); - static Error parse_tag_assign_eof(Stream *p_stream, int &line, String &r_err_str, Tag& r_tag, String &r_assign, Variant &r_value,ResourceParser *p_res_parser=NULL); + static Error parse_tag(Stream *p_stream, int &line, String &r_err_str,Tag& r_tag,ResourceParser *p_res_parser=NULL,bool p_simple_tag=false); + static Error parse_tag_assign_eof(Stream *p_stream, int &line, String &r_err_str, Tag& r_tag, String &r_assign, Variant &r_value,ResourceParser *p_res_parser=NULL,bool p_simple_tag=false); static Error parse_value(Token& token,Variant &value, Stream *p_stream, int &line, String &r_err_str,ResourceParser *p_res_parser=NULL); static Error get_token(Stream *p_stream,Token& r_token,int &line,String &r_err_str);