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

StringEscapeUtils.escapeJavaScript() method did not escape '/' into '\/', it will make IE render page uncorrectly

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 2.3
    • 2.4
    • None
    • None
    • JDK1.5 + commons-lang-2.3.jar + IE 6.0

    Description

      If Javascripts including'/', IE will parse the scripts uncorrectly, actually '/' should be escaped to '\/'.
      For example, document.getElementById("test").value = '<script>alert(\'aaa\');</script>';this expression will make IE render page uncorrect, it should be document.getElementById("test").value = '<script>alert(\'aaa\');<\/script>';

      Btw, Spring's JavascriptEscape behavor is correct.
      Try to run below codes, you will find the difference:
      String s = "<script>alert('aaa');</script>";
      String str = org.springframework.web.util.JavaScriptUtils.javaScriptEscape(s);
      System.out.println("Spring JS Escape : "+str);
      str = org.apache.commons.lang.StringEscapeUtils.escapeJavaScript(s);
      System.out.println("Apache Common Lang JS Escape : "+ str);

      Attachments

        1. patch.txt
          2 kB
          Scott Bassin

        Issue Links

          Activity

            People

              Unassigned Unassigned
              situch Situ Chenghao
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: