Infinite loop when using replace function

Infinite loop when using replace function

 I have tried multiple ways to get zoho to stop replacing text when the first replacement is done, but cannot get it to work.

The code I have right now in the on user input section of the Reference Name 1 field is:

   
  1. refName=input.Reference_Name_1;
  2. if (input.Reference_Name_1.contains(" "))
  3. {
  4. refNameReplace=(refName).replaceFirst(" ","%20");
  5. input.Reference_Name_1=refNameReplace;
  6. }
  7. else
  8. {
  9. }
but it does not seem to stop the loop.

Can anyone spot the error in this code that is not stopping the function? or is there a bug?

Thanks,

Mike