Uploaded image for project: 'Commons Lang'
  1. Commons Lang
  2. LANG-421

StringEscapeUtils.escapeJava(String) escapes '/' characters

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Blocker
    • Resolution: Fixed
    • 2.4
    • 2.5
    • lang.*
    • None

    Description

      Commons Lang 2.4 StringEscapeUtils.escapeJava(String) now escapes '/' characters, which is not a valid "escapable" character in Java strings. I haven't tried the other Java escape/unescape methods to see if they have a similar problem, or that only Java "escapable" characters are escaped by escapeJava(String).

      This bug may have appeared as an unintended side-effect of the fix for LANG-363.

      Also the javadoc for escapeJava is now a little off, in that '/' should now be included in the sentence describing the differences between Java and Javascript strings, with respect to escaping rules.

      The following is a JUnit3 test demonstrating the bug.

      import junit.framework.TestCase;

      import org.apache.commons.lang.StringEscapeUtils;

      public class StringEscapeUtilsTest extends TestCase {
      public void testEscapeJavaWithSlash()

      { final String input = "String with a slash (/) in it"; final String expected = input; final String actual = StringEscapeUtils.escapeJava( input ); /** * In 2.4 StringEscapeUtils.escapeJava(String) escapes '/' characters, * which are not a valid character to escape in a Java string. */ assertEquals( expected, actual ); }

      }

      Attachments

        1. StringEscapeUtilsTest.java
          0.6 kB
          Steve Hanmann

        Issue Links

          Activity

            People

              ggregory Gary D. Gregory
              shanmann Steve Hanmann
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: