commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Woonsan Ko (JIRA)" <j...@apache.org>
Subject [jira] [Closed] (LANG-1158) StrSubstitutor - escape character not working just before a variable
Date Thu, 23 Jul 2015 20:31:04 GMT

     [ https://issues.apache.org/jira/browse/LANG-1158?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Woonsan Ko closed LANG-1158.
----------------------------
    Resolution: Not A Problem

> StrSubstitutor - escape character not working just before a variable
> --------------------------------------------------------------------
>
>                 Key: LANG-1158
>                 URL: https://issues.apache.org/jira/browse/LANG-1158
>             Project: Commons Lang
>          Issue Type: Bug
>    Affects Versions: 3.4
>            Reporter: Woonsan Ko
>
> I tried to use the following, expecting "...ick brown fox paid $20.00 to jump over the
la…":
> {code}
>     // In org.apache.commons.lang3.text.StrSubstitutorTest.java locally
>     // after cloning https://github.com/woonsan/commons-lang.
>     @Test
>     public void testReplaceEscapingDollarSign() {
>         values.put("amount", "20.00");
>         doTestReplace("The quick brown fox paid $20.00 to jump over
> the lazy dog.",
>                       "The ${animal} paid $$${amount} to jump over the
> ${target}.", true);
>     }
> {code}
> {noformat}
> (I put double dollar signs like $$${amount} because $ is the default escape character.)
> Because I put three dollar signs in total, it should give one dollar sign followed by
the resolved amount value: "$20.00".
> But, the result was:"...ick brown fox paid $${amount} to jump over the la…".
> {noformat}
> I also tried using a different escape character like this:
> {code}
>     @Test
>     public void testReplaceEscapingDollarSign() {
>         values.put("amount", "20.00");
>         final StrSubstitutor sub = new StrSubstitutor(values);
>         sub.setEscapeChar('<');
>         String replaceTemplate = "The <${animal} jumps over the ${target}.";
>         String expectedResult = "The ${animal} jumps over the lazy dog.";
>         String replacedResult = sub.replace(replaceTemplate);
>         assertEquals(expectedResult, replacedResult);
>         replaceTemplate = "The ${animal} paid <$${amount} to jump over the ${target}.";
>         expectedResult = "The quick brown fox paid $20.00 to jump over the lazy dog.";
>         replacedResult = sub.replace(replaceTemplate);
>         assertEquals(expectedResult, replacedResult);
>     }
> {code}
> However, it fails like this:
> {noformat}
> Tests run: 41, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.048 sec <<<
FAILURE! - in org.apache.commons.lang3.text.StrSubstitutorTest
> testReplaceEscapingDollarSign(org.apache.commons.lang3.text.StrSubstitutorTest)  Time
elapsed: 0.009 sec  <<< FAILURE!
> org.junit.ComparisonFailure: expected:<...uick brown fox paid []$20.00 to jump over
...> but was:<...uick brown fox paid [<]$20.00 to jump over ...>
> 	at org.junit.Assert.assertEquals(Assert.java:115)
> 	at org.junit.Assert.assertEquals(Assert.java:144)
> 	at org.apache.commons.lang3.text.StrSubstitutorTest.testReplaceEscapingDollarSign(StrSubstitutorTest.java:182)
> {noformat}
> {noformat}
> The second assertion failed. So, it seems working in case of "<${animal}", but not
working in case of "<$${amount}".
> {noformat}
> I think escape character handling is inconsistent.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message