[
https://issues.apache.org/jira/browse/TEXT-223?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Cyril de Catheu updated TEXT-223:
---------------------------------
Description:
*Issue*
StringSubstitutor can perform [recursive variable
replacements|https://commons.apache.org/proper/commons-text/apidocs/org/apache/commons/text/StringSubstitutor.html#:~:text=recursive].
If there is a cycle, an IllegalStateException is thrown.
When using StringSubstitutor with recursive substitution disabled, an exception
is still thrown in case of cycles.
*Expected behavior*
No exception should be thrown. There is no cycle because the replacement is
not recursive.
*How to reproduce*
{code:java}
import java.util.Map;
import org.apache.commons.text.StringSubstitutor;
public class TestCycles {
public static void main(String[] args) {
Map<String, Object> cycleMap = Map.of("cycle", "${cycle}");
StringSubstitutor sub = new
StringSubstitutor(cycleMap).setEnableSubstitutionInVariables(false);
String res = sub.replace("my template ${cycle}");
}
}
{code}
Will throw
{code:java}
java.lang.IllegalStateException: Infinite loop in property interpolation of my
template ${cycle}: cycle.{code}
was:
*Issue*
StringSubstitutor can perform [recursive variable
replacements|https://commons.apache.org/proper/commons-text/apidocs/org/apache/commons/text/StringSubstitutor.html#:~:text=recursive].
If there is a cycle, an IllegalStateException is thrown.
When using StringSubstitutor with recursive substitution disabled, an exception
is still thrown in case of cycles.
*Expected behavior*
No exception should be thrown. There is no cycle because the replacement is
not recursive.
*How to reproduce*
```
import java.util.Map;
import org.apache.commons.text.StringSubstitutor;
public class TestCycles {
public static void main(String[] args) {
Map<String, Object> cycleMap = Map.of("cycle", "${cycle}");
StringSubstitutor sub = new
StringSubstitutor(cycleMap).setEnableSubstitutionInVariables(false);
String res = sub.replace("my template ${cycle}");
}
}
```
Will throw
```
java.lang.IllegalStateException: Infinite loop in property interpolation of my
template ${cycle}: cycle.
```
> StringSubstitutor checks for cycles even if recursive substitution is disabled
> ------------------------------------------------------------------------------
>
> Key: TEXT-223
> URL: https://issues.apache.org/jira/browse/TEXT-223
> Project: Commons Text
> Issue Type: Bug
> Affects Versions: 1.10.0
> Reporter: Cyril de Catheu
> Priority: Minor
>
> *Issue*
> StringSubstitutor can perform [recursive variable
> replacements|https://commons.apache.org/proper/commons-text/apidocs/org/apache/commons/text/StringSubstitutor.html#:~:text=recursive].
>
> If there is a cycle, an IllegalStateException is thrown.
> When using StringSubstitutor with recursive substitution disabled, an
> exception is still thrown in case of cycles.
> *Expected behavior*
> No exception should be thrown. There is no cycle because the replacement is
> not recursive.
> *How to reproduce*
> {code:java}
> import java.util.Map;
> import org.apache.commons.text.StringSubstitutor;
> public class TestCycles {
> public static void main(String[] args) {
> Map<String, Object> cycleMap = Map.of("cycle", "${cycle}");
> StringSubstitutor sub = new
> StringSubstitutor(cycleMap).setEnableSubstitutionInVariables(false);
> String res = sub.replace("my template ${cycle}");
> }
> }
> {code}
> Will throw
> {code:java}
> java.lang.IllegalStateException: Infinite loop in property interpolation of
> my template ${cycle}: cycle.{code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)