Skip to content

Commit c612512

Browse files
committed
8296660: Swing HTML table with omitted closing tags misparsed
Reviewed-by: prr, jdv
1 parent 56048f9 commit c612512

File tree

2 files changed

+75
-1
lines changed

2 files changed

+75
-1
lines changed

src/java.desktop/share/classes/javax/swing/text/html/parser/Parser.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -703,11 +703,12 @@ boolean legalElementContext(Element elem) throws ChangedCharSetException {
703703
}
704704
if (!s.terminate() || (strict && !s.elem.omitEnd())) {
705705
break;
706-
} else if (s.terminate()) {
706+
} else if (s.terminate() && !s.elem.omitEnd()) {
707707
// Since the current tag is not valid in current context
708708
// as otherwise s.advance(elem) would have returned true
709709
// so check if the stack is to be terminated
710710
// in which case return false
711+
// but not if the closing tag is optional like tr,th,td
711712
return false;
712713
}
713714
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
/*
24+
* @test
25+
* @bug 8296660
26+
* @library /java/awt/regtesthelpers
27+
* @build PassFailJFrame
28+
* @summary Verifies Swing HTML table with omitted closing tags parsed correctly
29+
* @run main/manual TestHtmlOptionalClosingTag
30+
*/
31+
32+
import javax.swing.JFrame;
33+
import javax.swing.JLabel;
34+
import javax.swing.SwingUtilities;
35+
36+
public class TestHtmlOptionalClosingTag {
37+
38+
private static JFrame frame;
39+
40+
private static final String INSTRUCTIONS =
41+
" A Swing JLabel with a two-column HTML table is shown\n " +
42+
" If the table is shown without any alignment issue\n " +
43+
" then press Pass, otherwise test fails";
44+
45+
public static void createAndShowGUI() {
46+
frame = new JFrame();
47+
String html = "<html><table>" +
48+
"<tr><th align=right>Name:<td>sync-001.mp4" +
49+
"<tr><th align=right>Modified:<td>2017-Jul-31, 00:14:55" +
50+
"<tr><th align=right>File size:<td>3.1 MB" +
51+
"<tr><th align=right>Duration:<td>1m03s" +
52+
"<tr><th align=right>Video:<td>854 x 480 - 16:9 - 30.0 fps - 271 kbps - H.264 / AVC" +
53+
"<tr><th align=right>Audio:<td>Stereo - 44100 Hz - 123 kbps - AAC";
54+
55+
JLabel label = new JLabel(html);
56+
frame.add(label);
57+
frame.setSize(400, 400);
58+
frame.setLocationRelativeTo(null);
59+
frame.setVisible(true);
60+
}
61+
62+
63+
public static void main(String[] argv) throws Exception {
64+
PassFailJFrame passFailJFrame = new PassFailJFrame(
65+
"SwingHtmlTable Test", INSTRUCTIONS, 5);
66+
SwingUtilities.invokeAndWait(() -> createAndShowGUI());
67+
PassFailJFrame.addTestWindow(frame);
68+
PassFailJFrame.positionTestWindow(
69+
frame, PassFailJFrame.Position.HORIZONTAL);
70+
passFailJFrame.awaitAndCheck();
71+
}
72+
}
73+

0 commit comments

Comments
 (0)