comparison libinterp/corefcn/ls-oct-text.cc @ 28179:bea3f8f96f7a stable

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.
author Olaf Till <i7tiol@t-online.de>
date Wed, 19 Apr 2017 15:06:31 +0200
parents a4268efb7334
children 7a8c69c4eb55
comparison
equal deleted inserted replaced
28178:0689e92f8b54 28179:bea3f8f96f7a
235 235
236 #define SUBSTRING_COMPARE_EQ(s, pos, n, t) (s.substr (pos, n) == (t)) 236 #define SUBSTRING_COMPARE_EQ(s, pos, n, t) (s.substr (pos, n) == (t))
237 237
238 std::string 238 std::string
239 read_text_data (std::istream& is, const std::string& filename, bool& global, 239 read_text_data (std::istream& is, const std::string& filename, bool& global,
240 octave_value& tc, octave_idx_type count) 240 octave_value& tc, octave_idx_type count,
241 const bool do_name_validation)
241 { 242 {
242 // Read name for this entry or break on EOF. 243 // Read name for this entry or break on EOF.
243 244
244 std::string name = extract_keyword (is, "name"); 245 std::string name = extract_keyword (is, "name");
245 246
250 filename.c_str ()); 251 filename.c_str ());
251 252
252 return ""; 253 return "";
253 } 254 }
254 255
255 if (! (name == CELL_ELT_TAG || octave::valid_identifier (name))) 256 if (name != CELL_ELT_TAG
257 && do_name_validation && ! octave::valid_identifier (name))
256 error ("load: invalid identifier '%s' found in file '%s'", 258 error ("load: invalid identifier '%s' found in file '%s'",
257 name.c_str (), filename.c_str ()); 259 name.c_str (), filename.c_str ());
258 260
259 // Look for type keyword. 261 // Look for type keyword.
260 262