Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6631246

swing html parser assumes commented css in style tags

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 7
    • client-libs

      FULL PRODUCT VERSION :
      java version "1.7.0-ea"
      Java(TM) SE Runtime Environment (build 1.7.0-ea-b22)
      Java HotSpot(TM) 64-Bit Server VM (build 11.0-b08, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Linux lithium 2.6.22-14-generic #1 SMP Sun Oct 14 21:45:15 GMT 2007 x86_64 GNU/Linux


      A DESCRIPTION OF THE PROBLEM :
      amazon.de sends out mail like this:

      ...
      <style type="text/css">
      ul#featuredLinks li {
      }

      div#footer {
          color: #999999;
          text-align: left;
      }

      table#snpmain tr td {
          font-size: 9pt;
      }
      </style>
      ...

      and Swing's HTML parser mistakenly displays the CSS content, presumably on the assumption that it's always surrounded by <!-- -->, which is often (but not always the case). to be able to cope with real-world HTML, Swing's HTML parser should ignore any content it sees while inside a STYLE tag.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      run the program pasted below.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      i'd expect to see one line, the "real content!" line.
      ACTUAL -
      i see the CSS in addition to the "real content!" line.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.swing.*;
      public class test extends JFrame {
       private JTextPane textPane;
       public test() {
        setContentPane(textPane = new JTextPane());
        textPane.setContentType("text/html");
        textPane.setText("<html><head></head><body><style type=\"text/css\">\nul#featuredLinks li {\n}\n\ndiv#footer {\n color: #999999;\n text-align: left;\n}\ntable#snpmain tr td {\n font-size: 9pt;\n}\n</style><p>real content!</body></html>");
        pack();
        setVisible(true);
       }
       public static void main(String[] args) {
        new test();
       }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      i can try to manually insert <!-- and -->, but that's error-prone. i haven't found anything better yet, which is why i'm writing this bug report.

            gsm Sergey Groznyh (Inactive)
            ryeung Roger Yeung (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: