# HG changeset patch # User Rik # Date 1512061987 28800 # Node ID 1212ffc13d24d4a881ee2a70759c18b227b181e6 # Parent 0771ce2d30ef3f9076321926188c9a223edc3b55 Fix concatenation of empty char matrices with other strings (bug #52542). * pt-mat.cc (tm_const::init): When executing special case of appending a 2-D char matrix, verify that the existing element is not empty before appending. If it is empty, just replace the existing element's dimension vector with the to-be-appended element's dimension vector. * parser.tst: Add concatenation tests for bug #52542 to other parser tests. diff -r 0771ce2d30ef -r 1212ffc13d24 libinterp/parse-tree/pt-mat.cc --- a/libinterp/parse-tree/pt-mat.cc Wed Nov 29 13:43:58 2017 -0800 +++ b/libinterp/parse-tree/pt-mat.cc Thu Nov 30 09:13:07 2017 -0800 @@ -638,11 +638,20 @@ else if (all_str && dv.ndims () == 2 && this_elt_dv.ndims () == 2) { - // FIXME: this is Octave's specialty. - // Character matrices allow rows of unequal length. - if (this_elt_nc > cols ()) - dv(1) = this_elt_nc; - dv(0) += this_elt_nr; + // This is Octave's specialty. + // Character matrices support rows of unequal length. + if (dv.any_zero ()) + { + // Empty existing element (bug #52542). + // Replace empty element with non-empty one. + dv = this_elt_dv; + } + else + { + if (this_elt_nc > cols ()) + dv(1) = this_elt_nc; + dv(0) += this_elt_nr; + } } else if ((! any_class) && (! dv.hvcat (this_elt_dv, 0))) eval_error ("vertical dimensions mismatch", dv, this_elt_dv); diff -r 0771ce2d30ef -r 1212ffc13d24 test/parser.tst --- a/test/parser.tst Wed Nov 29 13:43:58 2017 -0800 +++ b/test/parser.tst Thu Nov 30 09:13:07 2017 -0800 @@ -326,3 +326,10 @@ ## Maybe unnecessary, but check that further changes to parser don't ## invalidate error handling (bug #46534). #!error z = [1, 2; 3] + +## FIXME: We need a sequence of concatenation tests since this seems +## to be a frequently reported source of incompatibilities w/Matlab +## Check concatenation of empty char matrices (bug #52542) +%!assert (double ([char(ones(0,3)); 'A']), 65) +%!assert (double ([char(ones(0,3)); char(ones(2,0)); 'A']), 65) +