Hello,

I shared this issue on the user ML a few weeks ago.
If it's ok I'll start working on a fix for this.
Ticket is here https://issues.apache.org/jira/browse/TEXT-223.

Happy holidays.

---------- Forwarded message ---------
From: Cyril de Catheu <cy...@startree.ai>
Date: Fri, Nov 4, 2022 at 12:12 AM
Subject: [text] StringSubstitutor checks for cycles even if substitution in
variables is disabled
To: <u...@commons.apache.org>


Hello,

I'm trying to use StringSubstitutor. Substitution in variables (recursive
substitution) is disabled.
When I run with a variable cycle, I don't expect an infinite loop because
recursive substitution is disabled. But I still get the exception:
java.lang.IllegalStateException: Infinite loop in property interpolation of
my template ${cycle}: cycle.

See example code below.

import java.util.Map;
import org.apache.commons.text.StringSubstitutor;

public class TestCycles {

  public static void main(String[] args) {
    final Map<String, Object> cycleMap = Map.of("cycle", "${cycle}");
    final StringSubstitutor sub = new StringSubstitutor(cycleMap)
        .setEnableSubstitutionInVariables(false);
      String res =  sub.replace("my template ${cycle}");
  }
}


Is this the expected behavior, or do you think this should be fixed?

Thanks.

-- 

[image: StarTree] <https://startree.ai>
Cyril de Catheu
Software Engineer
+33 (684) 829-908 <+33+(684)+829-908>
Follow us: [image: RSS] <https://www.startree.ai/blogs>[image: LinkedIn]
<https://www.linkedin.com/company/startreedata/>[image: Twitter]
<https://twitter.com/startreedata>[image: Slack]
<https://stree.ai/slack>[image:
YouTube] <https://youtube.com/StarTreeData>

[image: Try StarTree Cloud Today]
<https://get.startree.ai/startree-cloud?utm_campaign=byoc-edition-of-startree-cloud&utm_source=email&utm_content=startree-employee-email-signatures>

Reply via email to