# HG changeset patch # User Olaf Till # Date 1492607191 -7200 # Node ID ef349f5c320bc3c9755afe7b4acd73fb54013b06 # Parent 478ad929e77a2bc8966f343a2ec8770f6701ced8 Load structures with arbitrary string fieldnames (bug #50831, bug #46645). * ls-oct-text.h, ls-oct-text.cc (read_text_data): Consider additional optional bool argument to skip validation of input name. * ov-struct.cc (octave_struct::load_ascii, octave_scalar_struct::load_ascii): Call read_text_data with additional argument (skip_validation), set to true. * test/bug-50831/bug-50831.tst, test/bug-50831/module.mk: New test files. diff -r 478ad929e77a -r ef349f5c320b libinterp/corefcn/ls-oct-text.cc --- a/libinterp/corefcn/ls-oct-text.cc Sat Mar 14 20:23:01 2020 -0700 +++ b/libinterp/corefcn/ls-oct-text.cc Wed Apr 19 15:06:31 2017 +0200 @@ -237,7 +237,8 @@ std::string read_text_data (std::istream& is, const std::string& filename, bool& global, - octave_value& tc, octave_idx_type count) + octave_value& tc, octave_idx_type count, + const bool do_name_validation) { // Read name for this entry or break on EOF. @@ -252,7 +253,8 @@ return ""; } - if (! (name == CELL_ELT_TAG || octave::valid_identifier (name))) + if (name != CELL_ELT_TAG + && do_name_validation && ! octave::valid_identifier (name)) error ("load: invalid identifier '%s' found in file '%s'", name.c_str (), filename.c_str ()); diff -r 478ad929e77a -r ef349f5c320b libinterp/corefcn/ls-oct-text.h --- a/libinterp/corefcn/ls-oct-text.h Sat Mar 14 20:23:01 2020 -0700 +++ b/libinterp/corefcn/ls-oct-text.h Wed Apr 19 15:06:31 2017 +0200 @@ -53,7 +53,8 @@ extern OCTINTERP_API std::string read_text_data (std::istream& is, const std::string& filename, bool& global, - octave_value& tc, octave_idx_type count); + octave_value& tc, octave_idx_type count, + const bool do_name_validation = true); extern OCTINTERP_API bool save_text_data (std::ostream& os, const octave_value& val_arg, diff -r 478ad929e77a -r ef349f5c320b libinterp/octave-value/ov-struct.cc --- a/libinterp/octave-value/ov-struct.cc Sat Mar 14 20:23:01 2020 -0700 +++ b/libinterp/octave-value/ov-struct.cc Wed Apr 19 15:06:31 2017 +0200 @@ -769,8 +769,7 @@ bool dummy; // recurse to read cell elements - std::string nm - = read_text_data (is, "", dummy, t2, j); + std::string nm = read_text_data (is, "", dummy, t2, j, false); if (! is) break; @@ -1432,7 +1431,7 @@ // recurse to read cell elements std::string nm - = read_text_data (is, "", dummy, t2, j); + = read_text_data (is, "", dummy, t2, j, false); if (! is) break; diff -r 478ad929e77a -r ef349f5c320b test/bug-50831/bug-50831.tst --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/bug-50831/bug-50831.tst Wed Apr 19 15:06:31 2017 +0200 @@ -0,0 +1,10 @@ +%!test +%! filename = "save-text.var"; +%! s.("a-b") = "bad fieldname"; +%! unwind_protect +%! save ("-text", filename, "s"); +%! filevar = load (filename); +%! assert (filevar.s, s); +%! unwind_protect_cleanup +%! sts = unlink (filename); +%! end_unwind_protect diff -r 478ad929e77a -r ef349f5c320b test/bug-50831/module.mk --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/bug-50831/module.mk Wed Apr 19 15:06:31 2017 +0200 @@ -0,0 +1,4 @@ +bug_50831_TEST_FILES = \ + test/bug-50831/bug-50831.tst + +TEST_FILES += $(bug_50831_TEST_FILES)