You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Woonsan Ko (JIRA)" <ji...@apache.org> on 2015/07/23 16:34:05 UTC
[jira] [Created] (LANG-1158) StrSubstitutor - escape character not
working just before a variable
Woonsan Ko created LANG-1158:
--------------------------------
Summary: 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}
(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…".
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);
//...
}
{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}
I think there's a bug at least, regard escape character handling.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)