bugGNU Octave - Bugs: bug #53095, strsplit fails to split a string...

 
 

bug #53095: strsplit fails to split a string with a delimiter of '\n' (null character)

Submitter:  None
Submitted:  Thu 08 Feb 2018 02:36:16 PM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Unexpected Error or Warning
Status:  Fixed Assigned to:  None
Originator Name:  Alex A. Originator Email:  -email is unavailable-
Open/Closed:  * Closed Release:  * dev
Operating System:  * Any Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Tue 13 Feb 2018 11:11:56 PM UTC, comment #15: 

I checked in a change to expand octal sequences in regexprep (http://hg.savannah.gnu.org/hgweb/octave/rev/6e670c58c6f0).  Closing report again.

Rik <rik5>
Group administrator
Tue 13 Feb 2018 06:54:07 PM UTC, comment #14: 

Re-opening report for additional fix of NULL characters in replacement string of regexprep.

Rik <rik5>
Group administrator
Tue 13 Feb 2018 06:35:26 PM UTC, comment #13: 

@Rik Output in MATLAB 2016b

>> s = regexprep('A,A','A','B\000B')
s =
B B,B B
>> double(s)
ans =
    66     0    66    44    66     0    66


Anushi Maheshwari <anushi>
Tue 13 Feb 2018 05:17:38 PM UTC, comment #12: 

@Philip: could you test


s = regexprep ('A,A', 'A', 'B\000B')
double (s)


in Matlab 2018a?

I got a report that--contrary to comment #9--the output is


ans =
    66     0    66    44    66     0    66


This was with Matlab 2015b.

In fact, the above is what I would expect.  This is what Octave gives as well if the pattern is enclosed in double quotes.  This probably means the octal escape sequences are not being processed properly for the replacement string in regexprep.

Rik <rik5>
Group administrator
Mon 12 Feb 2018 09:04:50 PM UTC, comment #11: 

                                      < M A T L A B (R) >
                            Copyright 1984-2017 The MathWorks, Inc.
                             R2017b (9.3.0.713579) 64-bit (glnxa64)
                                       September 14, 2017

 
To get started, type one of these: helpwin, helpdesk, or demo.
For product information, visit www.mathworks.com.
 

>> str = [97, 0, 0, 98, 0, 0, 99];
>> str = char (str);
>> del = '\0';
>> [C, M] = strsplit (str, del);
>> double (M{1})


ans =

     0     0

>>


Michael Godfrey <godfrey>
Group Member
Mon 12 Feb 2018 07:57:58 PM UTC, comment #10: 

Not what I expected, but Matlab is often like that.  I checked in a significant change to handle NULL characters in the pattern, and in the return strings like match, tokens, named_tokens.  See http://hg.savannah.gnu.org/hgweb/octave/rev/00dfa167c1fe.

Marking as fixed and closing report.


Rik <rik5>
Group administrator
Mon 12 Feb 2018 07:20:39 PM UTC, comment #9: 


>> s = regexprep ('A,A', 'A', 'B\000B')
s = B000B,B000B
>> double (s)
ans =

   66   48   48   48   66   44   66   48   48   48   66


Anushi Maheshwari <anushi>
Mon 12 Feb 2018 07:04:51 PM UTC, comment #8: 

What about NULLs in the the replacement string of regexprep?

Could you test


s = regexprep ('A,A', 'A', 'B\000B')
double (s)



Rik <rik5>
Group administrator
Mon 12 Feb 2018 06:37:36 PM UTC, comment #7: 

Code from comment #4 in ML 2018a prerelease:

>> str = [97, 0, 0, 98, 0, 0, 99];
str = char (str);
del = '\0';
[C, M] = strsplit (str, del);
double (M{1})

ans =

     0     0


Philip Nienhuis <philipnienhuis>
Group Member
Mon 12 Feb 2018 05:16:30 PM UTC, comment #6: 

Octave still fails because I haven't checked my patch in.  I was waiting for the answer to the question in comment #4.  But I'm now certain that this is a separate issue with regexp that requires fixing.


Rik <rik5>
Group administrator
Mon 12 Feb 2018 09:56:03 AM UTC, comment #5: 

@Rik I tried running this in Octave and it is still returning same error as previous.


error: regexp: missing ) at position 1 of expression
error: called from
    strsplit at line 212 column 19


Also, to my suprise I have noted different behaviour of regexp


str='abc';
delim= '(())';
s=regexp(str, delim, 'split', 'match')
% Return Output
s=
{
        [1,1] = abc
}



str='abc';
delim='(()';
regexp(str, delim, 'split', 'match');
% Throws error
error: regexp: missing ) at position 3 of expression


Anushi Maheshwari <anushi>
Mon 12 Feb 2018 04:24:50 AM UTC, comment #4: 

I have a patch for the first part of this bug.  I'd like to know how Matlab handles the second output (matches).  Could someone run the following


str = [97, 0, 0, 98, 0, 0, 99];
str = char (str);
del = '\0';
[C, M] = strsplit (str, del);
double (M{1})


In Octave this is returning an empty matrix ([]), but as I understand this it should return [0 0].

Rik <rik5>
Group administrator
Fri 09 Feb 2018 07:49:33 AM UTC, comment #3: 

I can confirm on Linux/dev

If I remove ";" from
  del = [ "(" del ")+" ]
(line 210 in scripts/strings/strsplit.m)


C = strsplit(str,delimiter)
del = ()+
error: regexp: missing ) at position 1 of expression
error: called from
    strsplit at line 212 column 19



Dmitri.
--

Dmitri A. Sergatskov <dasergatskov>
Fri 09 Feb 2018 07:48:50 AM UTC, comment #2: 

Confirmed on Linux as well:


octave:1> asciicode = [97, 0, 0, 98, 0, 0, 99];
octave:2> str = char(asciicode);
octave:3> delimiter = '\0';
octave:4> C = strsplit(str,delimiter)
error: regexp: missing ) at position 1 of expression
error: called from
    strsplit at line 212 column 19


Avinoam Kalma <avinoam>
Group Member
Fri 09 Feb 2018 07:41:03 AM UTC, comment #1: 

Confirmed in dev version as well on Win7.

Release => Dev
Status => confirmed
OS provisionally still Windows

Philip Nienhuis <philipnienhuis>
Group Member
Thu 08 Feb 2018 02:36:16 PM UTC, original submission:  

Hello,

Here's the test code:

asciicode = [97, 0, 0, 98, 0, 0, 99];
str = char(asciicode);
delimiter = '\0';
C = strsplit(str,delimiter)


The result should be:

C =

    'a'    'b'    'c'


The code works fine in Matlab, but fails in Octave with the following error message:


error: regexp: missing ) at position 1 of expression
error: called from
    strsplit at line 212 column 19
    stringexperiment at line 7 column 3


Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by godfrey (Posted a comment)
  • -email is unavailable- added by anushi (Posted a comment)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by dasergatskov (Posted a comment)
  • -email is unavailable- added by avinoam (Posted a comment)
  • -email is unavailable- added by None (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 10 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2018-02-13 rik5 StatusIn Progress Fixed
        Open/ClosedOpen Closed
    2018-02-13 rik5 StatusFixed In Progress
        Open/ClosedClosed Open
    2018-02-12 rik5 StatusIn Progress Fixed
        Open/ClosedOpen Closed
    2018-02-12 rik5 StatusConfirmed In Progress
    2018-02-09 avinoam Operating SystemMicrosoft Windows Any
    2018-02-09 philipnienhuis StatusNone Confirmed
        Release4.2.1 dev

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code