commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Woonsan Ko (JIRA)" <>
Subject [jira] [Created] (LANG-1158) StrSubstitutor - escape character not working just before a variable
Date Thu, 23 Jul 2015 14:34:05 GMT
Woonsan Ko created LANG-1158:

             Summary: StrSubstitutor - escape character not working just before a variable
                 Key: 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…":

    // In locally
    // after cloning
    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);

(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:

    public void testReplaceEscapingDollarSign() {
        values.put("amount", "20.00");

        final StrSubstitutor sub = new StrSubstitutor(values);

        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);


However, it fails like this:

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(
	at org.junit.Assert.assertEquals(
	at org.apache.commons.lang3.text.StrSubstitutorTest.testReplaceEscapingDollarSign(

I think there's a bug at least, regard escape character handling.

This message was sent by Atlassian JIRA

View raw message