bugGNU Octave - Bugs: bug #45084, regexptranslate incorrectly...

 
 

bug #45084: regexptranslate incorrectly escapes "<" and ">", maybe others

Submitter:  Colin Macdonald <cbm>
Submitted:  Tue 12 May 2015 01:35:32 PM UTC
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment (Rich Markup)
   

Wed 13 May 2015 11:34:08 AM UTC, comment #2: 

Thank you for the quick fix!  Seems to work perfectly for my issue.

Colin Macdonald <cbm>
Tue 12 May 2015 03:49:08 PM UTC, comment #1: 

I'm pretty sure I was the one that coded that regular expression and I did it because it was simplest to escape everything that might be a regular expression, rather than to come up with a definitive list of the characters to escape.

But we could go the other way as well and list everything that seems like a possible pattern.  I made that change on the development branch here (http://hg.savannah.gnu.org/hgweb/octave/rev/89616a98b02e).  I also improved the speed of the 'wildcard' option by 44% while I was modifying the function.

I made the change on the development branch, but I will also pull it across to the stable branch.

Rik <rik5>
Group administrator
Tue 12 May 2015 01:35:32 PM UTC, original submission:  

regexptranslate has an "escape" mode which escapes characters.

The docs say: "special meaning for regular expressions are escaped so that they are treated literally."

But some characters without special meaning are incorrectly escaped:

>> s = '<><>'
s = <><>
>> re = regexptranslate ('escape', s)
re = \<\>\<\>
>> regexp(s, re)
ans = [](1x0)


('re' is just 's' again on Matlab and thus 're' does indeed match 's'.  I believe this is the correct behaviour).

I looked at the implementation and it does look wrong in that it escapes all non-word characters:


  elseif (strcmp ("escape", op))
    y = regexprep (s, '([^\w])', '\\$1');


This is https://github.com/catch22/octave-doctest/issues/42.

If someone confirms this, I will try to write a patch which explicitly lists all characters to be translated.

Colin Macdonald <cbm>

 

(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 rik5 (Posted a comment)
  • -email is unavailable- added by cbm (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 project members can vote.

     

     

     

     

    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2015-05-12 rik5 StatusNone Fixed
        Open/ClosedOpen Closed

    Back to the top

    Powered by Savane 3.12