[ 
https://issues.apache.org/jira/browse/TEXT-74?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16195906#comment-16195906
 ] 

ASF GitHub Bot commented on TEXT-74:
------------------------------------

GitHub user sermojohn opened a pull request:

    https://github.com/apache/commons-text/pull/68

    TEXT-74 Introduced new StrSubstitutor attribute to disable recursive 
substitution

    

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/sermojohn/commons-text TEXT-74

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/commons-text/pull/68.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #68
    
----
commit a25aa337f08e8cd0baad1d70565552c7dad91d5b
Author: Ioannis Sermetziadis <[email protected]>
Date:   2017-10-07T21:34:06Z

    TEXT-74 Added attribute for disabling the recursive substitution of 
variable values

----


> StrSubstitutor: Ability to turn off substitution in values
> ----------------------------------------------------------
>
>                 Key: TEXT-74
>                 URL: https://issues.apache.org/jira/browse/TEXT-74
>             Project: Commons Text
>          Issue Type: Improvement
>            Reporter: Arend v. Reinersdorff
>            Priority: Minor
>              Labels: features
>             Fix For: 1.x
>
>
> StrSubstitutor replaces variables in values. And currently there's no way to 
> turn this off.
> Why turn it off: I want to replace some variables in a simple template. Some 
> of the replacement values are arbitrary user input.
> At the moment I escape all dollar signs in the replacement values with "$$". 
> This is annoying. Especially as I use one template with variables as a value 
> for another variable. Here I have to escape twice.
> Here's some example code. At the moment it prints:
> {code}
> Hello Hamburg from Hamburg
> {code}
> The commented line is my suggestion for this feature. If it works, it should 
> print:
> {code}
> Hello ${city} from Hamburg
> {code}
> {code}
> // untrusted user input
> String userInputName = "${city}";
> String userInputCity = "Hamburg";
> Map<String, String> valueMap = new HashMap<>();
> valueMap.put("name", userInputName);
> valueMap.put("city", userInputCity);
> String source = "Hello ${name} from ${city}";
> StrSubstitutor strSubstitutor = new StrSubstitutor(valueMap);
> // strSubstitutor.setEnableSubstitutionInValues(false);
> System.out.println(strSubstitutor.replace(source));
> {code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to