facebookincubator / fastmod

A fast partial replacement for the codemod tool
Apache License 2.0
1.66k stars 41 forks source link

Infinite loop when REGEX also matches subst #16

Closed thieman closed 5 years ago

thieman commented 5 years ago

fastmod 0.2.6 on OS X

Create a file with the word "bacon" in it

Run the following:

fastmod 'ac' 'bacon'

Expected result: Substitution is processed once, changing the text to bbaconon

Actual result: Substitution is processed infinitely. If you select "Yes to all" you are treated to a very trippy experience in your terminal as fastmod expands the string as quickly as it can.

I'm not sure whether it's a welcome comparison, but codemod 'ac' 'bacon' produces the desired result, only processing the match once.

swolchok commented 5 years ago

codemod 'ac' 'bacon' produces the desired result, only processing the match once

I believe codemod -m 'ac' 'bacon' has the same problem.

I talked about this issue in my comment on https://github.com/facebookincubator/fastmod/pull/3 :

Our current policy is to act as though the user pressed y repeatedly. There is an infinite loop bug with A on master for both codemod and fastmod... The problem there is that the replacement matches the search pattern, so we continually replace our own replacement (and grow it).

It looks like I wrote that comment but never got around to implementing the unified advancement policy. I'll open a new issue to implement the unified advancement policy from that comment.