Ticket #2320 (closed defect: fixed)

Opened 8 years ago

Last modified 8 years ago

regexp replace only transforms the first occurence correctly

Reported by: ply Owned by: andrew_b
Priority: major Milestone: 4.7.4
Component: mcedit Version: 4.7.3
Keywords: Cc:
Blocked By: Blocking:
Branch state: Votes for changeset: committed-master committed-stable

Description

If the replacement string contains references to parenthesized substrings (\1, \2, ...), the first occurence is transformed correctly, but subsequent ones are replaced by the result from the first occurence. A comment at editcmd.c:1838 says

/* don't process string each time */

thus skips calling mc_search_prepare_replace_str more than once per search. This makes regexp replace fairly unusable.

Attachments

2320_regexp_replace.patch (2.6 KB) - added by andrew_b 8 years ago.

Change History

comment:1 Changed 8 years ago by andrew_b

Would you provide the step-by-step description how to reproduce this bug? What you expect and what you get?

comment:2 Changed 8 years ago by ply

To reproduce:

Create a file containing foo bar baz.

Do a replace with search string (\w+) and replacement string "\1".

The expected result is that each word will be quoted with double quotes.

Instead, the file will turn into "foo" "foo" "foo".

This feature used to work in 4.7.0.1.

comment:3 Changed 8 years ago by andrew_b

OK. Thanks!

Changed 8 years ago by andrew_b

comment:4 Changed 8 years ago by andrew_b

  • Keywords stable-candidate added

I've attached a patch. I'll create a branch today at evening.

comment:5 Changed 8 years ago by andrew_b

  • Owner set to andrew_b
  • Status changed from new to accepted
  • severity changed from no branch to on review

Created 2320_regexp_replace branch. Parent branch is master.
changeset:3b4f38fa10b37254e251b43d4c6a0942c244beb8

comment:6 Changed 8 years ago by andrew_b

  • Milestone changed from 4.7 to 4.7.4

comment:7 Changed 8 years ago by angel_il

  • Votes for changeset set to angel_il

comment:8 Changed 8 years ago by slavazanko

  • Votes for changeset changed from angel_il to angel_il slavazanko
  • severity changed from on review to approved

comment:9 Changed 8 years ago by andrew_b

  • Status changed from accepted to testing
  • Votes for changeset changed from angel_il slavazanko to committed-master committed-stable
  • Resolution set to fixed
  • severity changed from approved to merged

comment:10 Changed 8 years ago by andrew_b

  • Status changed from testing to closed

comment:11 Changed 8 years ago by andrew_b

  • Keywords stable-candidate removed
Note: See TracTickets for help on using tickets.