bugGNU Octave - Bugs: bug #40537, save() work incorrectly when...

 
 

bug #40537: save() work incorrectly when filename contain square brackets pair []

Submitter:  Eddy <count>
Submitted:  Sun 10 Nov 2013 03:37:26 PM UTC
   
 
Category:  Octave Function Severity:  2 - Minor
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Confirmed Assigned to:  None
Originator Name:  Open/Closed:  * Open
Release:  * dev Operating System:  * GNU/Linux
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Thu 01 Dec 2016 06:00:07 AM UTC, comment #4: 

A fix is simple, like the attached file.

The problem is as pointed out in comment #1 that this behavior is intended:

libinterp/corefcn/load-save.cc


  // Guard against things like 'save a*', which are probably mistakes...

  else if (i == argc - 1 && glob_pattern_p (argv[i]))
    print_usage ();


But I would argue that in MATLAB, save('a*') will simply save all variables to a file named "a*.mat", without a warning.

(file #39124)

Eddy <count>
Wed 23 Nov 2016 09:29:16 PM UTC, comment #3: 

This behavior is still present in Octave 4.2.0.

Hartmut <hardy>
Mon 11 Nov 2013 08:26:09 AM UTC, comment #2: 

In this case


> save ab*


I think we should save all variables to the file "ab*", since the document say


 -- Command:  save file
 -- Command:  save options file
 -- Command:  save options file V1 V2 ...
 -- Command:  save options file -struct STRUCT F1 F2 ...


It's the first form of this command.
The first non-option string is always a filename.

Well, yes, "ab*" is a bed name although.... or maybe make it a warning instead of error?

Eddy <count>
Sun 10 Nov 2013 03:55:10 PM UTC, comment #1: 

Confirmed on the development version.

Many programs are going to have trouble with file names containing square brackets, it's best to stick to portable file names.

That being said, your analysis looks right, the save function is interpreting the file name as a variable pattern because it looks like a glob string. The same error occurs if you try to save to a file containing an asterisk or a question mark.

There is a comment in the code that suggests this is done intentionally. Probably to prevent users from calling save with a pattern and no file name.

So if a user runs


> save ab*


should it save all variables to a file named "ab*", or should it error like it does today because that is probably not what they meant?

Mike Miller <mtmiller>
Group Member
Sun 10 Nov 2013 03:37:26 PM UTC, original submission:  

octave tell me "error: Invalid call to save." etc when I run


a=1; b=1;
save('a[s]')


The expected result is saving all variables into the file named "a[s]"
Problem also exist in version 3.6.2 and 3.4.3

Seems that it's relate to the wildcard patterns [ list ] match function in save().

Luckily, this works:


a=1; b=1;
save('a[s]','*')


Eddy <count>

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #39124:  fix_bug40537_v1.cset added by count (1022B - application/octet-stream)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by hardy (Posted a comment)
  • -email is unavailable- added by mtmiller (Posted a comment)
  • -email is unavailable- added by count (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 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2016-12-01 count Attached File- Added fix_bug40537_v1.cset, #39124
    2013-11-10 mtmiller Severity3 - Normal 2 - Minor
        StatusNone Confirmed

    Back to the top

    Powered by Savane 3.13-d3ae.
    Corresponding source code