bugGNU Octave - Bugs: bug #33611, Matlab-incompatible character...


bug #33611: Matlab-incompatible character string escape processing

Submitted by:  John W. Eaton <jwe>
Submitted on:  Tue 21 Jun 2011 03:10:03 PM UTC  
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  Closed
Release:  dev Operating System:  Any

Add a New Comment (Rich Markup)

You are not logged in

Please log in, so followups can be emailed to you.


( Jump to the original submission)

Fri 15 Mar 2013 01:50:52 PM UTC, comment #8: 

I just downloaded edit.m from:
(indicated as stable)

The "undo_string_escapes" seem to have fixed this problem and I am successfully able to specify the path as:
EDITOR('C:\Program Files (x86)\Vim\vim73\gvim.exe');

Thanks for following up.

Carl <costerwi>
Wed 13 Mar 2013 06:45:33 PM UTC, comment #7: 

Does the problem with edit.m and '\' still exist?

I notice that edit.m has been coded to use undo_string_escapes before calling sprintf.  This should mean that extra backslashes are inserted and then removed by sprintf so that the result is unchanged but the '%s' token can still be used by sprintf.  I used a recent changeset on the development branch for testing (16297:00da706fba48).

Rik <rik5>
Project Administrator
Thu 04 Oct 2012 07:54:28 PM UTC, comment #6: 

It's too bad Matlab compatibility has to make printf inconsistent with it's string quoting.  I don't think there's a good way to make the function smarter with this constraint.

Double quote, double backslash doesn't workaround.  I think the EDITOR function immediately performs escape processing and then always returns a single-quote result.

My workaround is to specify the directory using forward slash as the separator.  I'm using the mingw distribution 3.6.1 and this seems to work on my Windows7 x64 machine:

EDITOR('C:/Program Files (x86)/Vim/vim73/gvim.exe');

Carl <costerwi>
Thu 04 Oct 2012 02:01:33 PM UTC, comment #5: 

A character string using single quotes does not do any backslash escape processing.

But, when given a single quote character string, the printf functions do perform escape processing on the format argument.  That is required for Matlab compatibility.

One problem is what escape sequences should be recognized, and what should we do for those that are not recognized.  Maybe we shouldn't be warning about them, or dropping the \ character.

The problem with the edit function is that we want to handle %s in the EDITOR variable.  The easy way to do that is to use the EDITOR variable as a format in sprintf.  But as you see, that causes some trouble.  Can you avoid the problem by using double quotes and double backslashes:  "c:\\foo\\bar\\system\\editor"?

John W. Eaton <jwe>
Project Administrator
Thu 04 Oct 2012 01:45:29 PM UTC, comment #4: 

I think this is a related issue that breaks the edit.m command on Windows since my EDITOR specifies the full path using backslashes.  edit.m uses sprintf command but you can see the problem here:

octave:27> printf('single \quotes \should \not \escape!')
warning: unrecognized escape sequence `\q' -- converting to `q'
warning: unrecognized escape sequence `\s' -- converting to `s'
warning: unrecognized escape sequence `\e' -- converting to `e'
single quotes should
ot escape!octave:28>

Carl <costerwi>
Thu 05 Apr 2012 07:09:04 PM UTC, comment #3: 

Is the particular example an actual problem?  It appears that it might not even run on Matlab.  For example, what does Matlab do for

disp "foo\xar"

I would think it would produce an error because the string delimiter in Matlab is a single quote.  So it looks like the code to run would be

disp 'foo\xar'

and the eval version would be

eval ('disp ''foo\xar''')

which very properly doesn't do escape sequences.

Rik <rik5>
Project Administrator
Tue 28 Jun 2011 11:32:49 PM UTC, comment #2: 

Oops, no there is not.  The first is correct.  What was I thinking?  Is there no way to delete a comment from the bug tracker?

John W. Eaton <jwe>
Project Administrator
Tue 28 Jun 2011 11:30:36 PM UTC, comment #1: 

There is a typo in the description of the bug.  It should be

octave:6> eval ('"disp "foo\xar"')
warning: unrecognized escape sequence `\x' -- converting to `x'

John W. Eaton <jwe>
Project Administrator
Tue 21 Jun 2011 03:10:03 PM UTC, original submission:  

Octave processes string escapes in the following context:

octave:6> eval ('disp "foo\xar"')
warning: unrecognized escape sequence `\x' -- converting to `x'

This does not happen in Matlab (Matlab only processes string escapes in the format of a call to *printf).  This problem has consequences for command evaluation on Windows systems where backslash is used as a directory separator.

John W. Eaton <jwe>
Project Administrator


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

Attach Files:

No files currently attached


Depends on the following items: None found

   bug dependencies.


Carbon-Copy List
  • -email is unavailable- added by costerwi (Posted a comment)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by jwe (Submitted the item)

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.




    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2013-03-15 rik5 StatusNeed Info => Fixed
        Open/ClosedOpen => Closed
    2012-04-05 rik5 StatusNone => Need Info
    2012-03-25 rik5 Dependencies- => bugs #35911 is dependent

    Back to the top

    Powered by Savane 3.7