JDK-4695909 : JEditorPane fails to display HTML BODY when META tag included in HEAD section
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.4.0
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_nt,windows_2000
  • CPU: x86
  • Submitted: 2002-06-01
  • Updated: 2003-03-12
  • Resolved: 2003-03-12
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
5.0 tigerFixed
Related Reports
Duplicate :  
Relates :  
Description

Name: jl125535			Date: 05/31/2002


FULL PRODUCT VERSION :
java version "1.4.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)

FULL OPERATING SYSTEM VERSION :
Windows NT 4.0 SP6



EXTRA RELEVANT SYSTEM CONFIGURATION :
Dell Inspiron 7500 laptop.  384MB RAM.  PIII 450MHz.

A DESCRIPTION OF THE PROBLEM :
When the tag <meta http-equiv=Content-Type
content=text/html> is included in the HEAD section of an
HTML document passed as a string to jeditorpane.setText
(String) JEditorPane fails to render the body section
entirely.

It appears the JEditorPane class fails to properly output the body (and perhaps 
other sections?) when a META tag that specifies "http-equiv=Content-Type" is 
used.  Other META tags do not necessarily cause the problem.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Simply run the code provided.


EXPECTED VERSUS ACTUAL BEHAVIOR :

Expected:

The test program should display the following:

[jeditorpane.getText() produces:]
<html>
  <head>

  </head>
  <body>
    <p>
      Hello
    </p>
  </body>
</html>


Actual:

The test program displays the following:

[jeditorpane.getText() produces:]
<html>
  <head>

  </head>
  <body>
    <p>
  
    </p>
  </body>
</html>


This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import javax.swing.*;

public class TestJEditorPane {

	void test (String test_content) {
        JEditorPane jeditorpane = new JEditorPane();

        jeditorpane.setContentType ( "text/html" );
        jeditorpane.setText ( test_content );

        System.out.println ( "[This is the string used in setText(String):]" );
        System.out.println ( test_content );
        System.out.println ();
        System.out.println ( "[jeditorpane.getText() produces:]" );
        System.out.println ( jeditorpane.getText() );
    }

    TestJEditorPane () {

        /*                                   
         *    Test a very simple HTML String.
         */
        test ( "<HTML><HEAD></HEAD><BODY> Hello </BODY></HTML>" );
        System.out.println ( "-----------------------------------------------");

        /*  
         *    Try the same string but insert a META tag that specifies  
         *    http-equiv=Content-Type    in the HEAD section.  
         */
        test ( "<HTML><HEAD><META http-equiv=\"Content-Type\" "
              + "content=\"text/html\">"
              + "</HEAD><BODY><P>Hello</P></BODY></HTML>" );

        /* 
         *    Notice after calling test(String) this second time the word
         *    "Hello" is not in the String produced by getText() in
         *    JEditorPane.  This appears to be a bug.                
         */        
    }

    public static void main (String args[]) {

        /* call default constructor */
        TestJEditorPane t = new TestJEditorPane ();
    }

} // end class


---------- END SOURCE ----------

CUSTOMER WORKAROUND :
I can parse the HTML String and remove everything in the
HEAD section before calling JEditorPane.setText(String).

This is somewhat cumbersome because in some cases we are
working with a high volume of files and very frequently
refreshing.  This does have an impact on performance.
(Review ID: 138737) 
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: tiger FIXED IN: tiger INTEGRATED IN: tiger tiger-b03
14-06-2004

EVALUATION Name: slR10134 Date: 08/19/2002 (###@###.###) This bug depends on bug #4625388 and complete fix (e.g. for cases when content type eqauls not only "text/html") is impossible without fix for 4625388. But it is possible to fix bug for case of "text/html" which is most frequently encountered. The reason of the bug is the following: when parser encounters attribute "http-equiv" in tag <meta> it throws ChangedCharSetException that causes remainder of document is not processed. The idea of suggested fix is to throw exception only if content type doesn't equal to "text/html" and "text/plain". ======================================================================
11-06-2004

SUGGESTED FIX Name: slR10134 Date: 08/19/2002 ------- DocumentParser.java ------- *** /tmp/sccs.ZNaWnv ������ ������ 16 17:14:14 2002 --- DocumentParser.java ������ ������ 16 16:57:44 2002 *************** *** 166,172 **** String content = (String)atts.getAttribute(HTML.Attribute.CONTENT); if (content != null) { if ("content-type".equalsIgnoreCase((String)atts.getAttribute(HTML.Attribute.HTTPEQ UIV))) { ! throw new ChangedCharSetException(content, false); } else if ("charset" .equalsIgnoreCase((String)atts.getAttribute(HTML.Attribute.HTTPEQUIV))) { throw new ChangedCharSetException(content, true); } --- 166,175 ---- String content = (String)atts.getAttribute(HTML.Attribute.CONTENT); if (content != null) { if ("content-type".equalsIgnoreCase((String)atts.getAttribute(HTML.Attribute.HTTPEQ UIV))) { ! if (!content.equalsIgnoreCase("text/html") && ! !content.equalsIgnoreCase("text/plain")) { ! throw new ChangedCharSetException(content, false); ! } } else if ("charset" .equalsIgnoreCase((String)atts.getAttribute(HTML.Attribute.HTTPEQUIV))) { throw new ChangedCharSetException(content, true); } ======================================================================
11-06-2004