undefect. CWE-407 — 63 sites patched across 27 ecosystems
Authors: russell@unturf.com · brackishbert@gmail.com · foxhop.net · TimeHexOn.com Patches, unit tests, benchmarks, whitepaper, and outreach briefs. Public domain — no copyright claimed. Use freely.
This commit is contained in:
commit
0a580b313d
70422 changed files with 17213626 additions and 0 deletions
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import javax.swing.text.html.parser.ContentModel;
|
||||
import javax.swing.text.html.parser.DTD;
|
||||
import javax.swing.text.html.parser.Element;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8074956
|
||||
* @author Alexey Ivanov
|
||||
* @summary Tests correct handling of additional HTML elements in ContentModel
|
||||
* @run main bug8074956
|
||||
*/
|
||||
public class bug8074956 {
|
||||
public static void main(String[] args) throws Exception {
|
||||
final DTD html32 = DTD.getDTD("html32");
|
||||
ContentModel contentModel = new ContentModel('&', new ContentModel());
|
||||
|
||||
Element elem1 = html32.getElement("html-element");
|
||||
contentModel.first(elem1);
|
||||
|
||||
Element elem2 = html32.getElement("test-element");
|
||||
// Shouldn't throw ArrayIndexOutOfBoundsException
|
||||
contentModel.first(elem2);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 6836089
|
||||
* @summary Tests correct parsing of characters outside Base Multilingual Plane
|
||||
* @author Vladislav Karnaukhov
|
||||
*/
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.text.html.*;
|
||||
|
||||
public class bug6836089 {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
SwingUtilities.invokeAndWait(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
JTextPane htmlPane = new JTextPane();
|
||||
htmlPane.setEditorKit(new HTMLEditorKit());
|
||||
|
||||
htmlPane.setText("<html><head></head><body>𠀀</body></html>");
|
||||
String str = htmlPane.getText();
|
||||
if (str.contains("�")) {
|
||||
throw new RuntimeException("Test failed");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* Copyright (c) 2010, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/* @test
|
||||
@bug 6990651
|
||||
@summary Regression: NPE when refreshing embedded window since 6u22-b01
|
||||
@author Pavel Porvatov
|
||||
@modules java.desktop/sun.awt
|
||||
*/
|
||||
import sun.awt.SunToolkit;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class bug6990651 {
|
||||
private static volatile JEditorPane editor;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
SwingUtilities.invokeAndWait(new Runnable() {
|
||||
public void run() {
|
||||
editor = new JEditorPane("text/html", "Hello world!");
|
||||
}
|
||||
});
|
||||
|
||||
Thread thread = new Thread(new ThreadGroup("Some ThreadGroup"), new Runnable() {
|
||||
public void run() {
|
||||
SunToolkit.createNewAppContext();
|
||||
|
||||
try {
|
||||
SwingUtilities.invokeAndWait(new Runnable() {
|
||||
public void run() {
|
||||
editor.setText("Hello world!");
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
thread.start();
|
||||
thread.join();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/* @test
|
||||
@bug 7003777
|
||||
@summary Nonexistent html entities not parsed properly.
|
||||
@author Pavel Porvatov
|
||||
*/
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.text.BadLocationException;
|
||||
|
||||
public class bug7003777 {
|
||||
private static final String[] TEST_STRINGS = {
|
||||
"&a",
|
||||
"&aa",
|
||||
"&a;",
|
||||
"&aa;",
|
||||
};
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
SwingUtilities.invokeAndWait(new Runnable() {
|
||||
public void run() {
|
||||
JTextPane pane = new JTextPane();
|
||||
|
||||
pane.setContentType("text/html");
|
||||
|
||||
for (String testString : TEST_STRINGS) {
|
||||
pane.setText(testString);
|
||||
|
||||
String parsedText;
|
||||
|
||||
try {
|
||||
parsedText = pane.getDocument().getText(0, pane.getDocument().getLength());
|
||||
} catch (BadLocationException e) {
|
||||
throw new RuntimeException("The test failed.", e);
|
||||
}
|
||||
|
||||
if (parsedText.charAt(0) != '\n') {
|
||||
throw new RuntimeException("The first char should be \\n");
|
||||
}
|
||||
|
||||
parsedText = parsedText.substring(1);
|
||||
|
||||
if (!testString.equals(parsedText)) {
|
||||
throw new RuntimeException("The '" + testString +
|
||||
"' string wasn't parsed correctly. Parsed value is '" + parsedText + "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 7011777
|
||||
* @summary Tests correct parsing of a HTML comment inside 'script' tags
|
||||
* @author Dmitry Markov
|
||||
*/
|
||||
|
||||
import javax.swing.text.html.HTMLEditorKit;
|
||||
import javax.swing.text.html.parser.ParserDelegator;
|
||||
import java.io.StringReader;
|
||||
|
||||
public class bug7011777 {
|
||||
static String comment = "<!--\n" +
|
||||
"function foo() {\n" +
|
||||
" var tag1 = \"</script>\";\n" +
|
||||
" var tag2 = \"<div>\";\n" +
|
||||
" var tag3 = \"</div>\";\n" +
|
||||
" var tag4 = \"<script>\";\n" +
|
||||
"}\n" +
|
||||
"// -->";
|
||||
static String html = "<script>" + comment + "</script>";
|
||||
public static void main(String[] args) throws Exception {
|
||||
new ParserDelegator().parse(new StringReader(html), new MyParserCallback(), true);
|
||||
}
|
||||
|
||||
static class MyParserCallback extends HTMLEditorKit.ParserCallback {
|
||||
|
||||
@Override
|
||||
public void handleComment(char[] data, int pos) {
|
||||
String commentWithoutTags = comment.substring("<!--".length(), comment.length() - "-->".length());
|
||||
String str = new String(data);
|
||||
if (!commentWithoutTags.equals(str)) {
|
||||
System.out.println("Sample string:\n" + commentWithoutTags);
|
||||
System.out.println("Returned string:\n" + str);
|
||||
throw new RuntimeException("Test Failed, sample and returned strings are mismatched!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,307 @@
|
|||
/*
|
||||
* Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @key headful
|
||||
* @bug 7165725
|
||||
* @summary Tests if HTML parser can handle successive script tags in a line
|
||||
* and it does not call false text callback after script tags.
|
||||
* @run main bug7165725
|
||||
*/
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Robot;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import javax.swing.*;
|
||||
import javax.swing.text.AbstractDocument.AbstractElement;
|
||||
import javax.swing.text.AbstractDocument;
|
||||
import javax.swing.text.Document;
|
||||
import javax.swing.text.MutableAttributeSet;
|
||||
import javax.swing.text.html.HTML;
|
||||
import javax.swing.text.html.HTMLDocument;
|
||||
import javax.swing.text.html.HTMLEditorKit;
|
||||
import javax.swing.text.html.parser.ParserDelegator;
|
||||
|
||||
public class bug7165725 extends JFrame {
|
||||
private static class GoldenElement {
|
||||
|
||||
private String goldenName;
|
||||
private List<GoldenElement> goldenChildren;
|
||||
|
||||
GoldenElement(String goldenName, GoldenElement... goldenChildren){
|
||||
this.goldenName = goldenName;
|
||||
if (goldenChildren != null) {
|
||||
this.goldenChildren = Arrays.asList(goldenChildren);
|
||||
} else {
|
||||
this.goldenChildren = new ArrayList<>();
|
||||
}
|
||||
}
|
||||
|
||||
// throws RuntimeException if not ok
|
||||
public void checkStructureEquivalence(AbstractDocument.AbstractElement elem) {
|
||||
String name = elem.getName();
|
||||
if (!goldenName.equals(name)) {
|
||||
throw new RuntimeException("Bad structure: expected element name is '" + goldenName + "' but the actual name was '" + name + "'.");
|
||||
}
|
||||
int goldenChildCount = goldenChildren.size();
|
||||
int childCount = elem.getChildCount();
|
||||
if (childCount != goldenChildCount) {
|
||||
System.out.print("D: children: ");
|
||||
for (int i = 0; i < childCount; i++) {
|
||||
System.out.print(" " + elem.getElement(i).getName());
|
||||
}
|
||||
System.out.println("");
|
||||
System.out.print("D: goldenChildren: ");
|
||||
for (GoldenElement ge : goldenChildren) {
|
||||
System.out.print(" " + ge.goldenName);
|
||||
}
|
||||
System.out.println("");
|
||||
|
||||
throw new RuntimeException("Bad structure: expected child count of element '" + goldenName + "' is '" + goldenChildCount + "' but the actual count was '" + childCount + "'.");
|
||||
}
|
||||
for (int i = 0; i < childCount; i++) {
|
||||
AbstractDocument.AbstractElement nextElem = (AbstractDocument.AbstractElement) elem.getElement(i);
|
||||
GoldenElement goldenElement = goldenChildren.get(i);
|
||||
goldenElement.checkStructureEquivalence(nextElem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private JEditorPane editorPane;
|
||||
public void execute(final String urlStr, final GoldenElement goldenElement) throws Exception {
|
||||
System.out.println();
|
||||
System.out.println("***** TEST: " + urlStr + " *****");
|
||||
System.out.println();
|
||||
|
||||
SwingUtilities.invokeAndWait(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
editorPane = new JEditorPane();
|
||||
editorPane.setEditorKit(new HTMLEditorKit() {
|
||||
public Document createDefaultDocument() {
|
||||
AbstractDocument doc =
|
||||
(AbstractDocument) super.createDefaultDocument();
|
||||
doc.setAsynchronousLoadPriority(-1);
|
||||
return doc;
|
||||
}
|
||||
});
|
||||
editorPane.setPage(new URL(urlStr));
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException("Test failed", ex);
|
||||
}
|
||||
editorPane.setEditable(false);
|
||||
JScrollPane scroller = new JScrollPane();
|
||||
JViewport vp = scroller.getViewport();
|
||||
vp.add(editorPane);
|
||||
add(scroller, BorderLayout.CENTER);
|
||||
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||
setSize(400, 400);
|
||||
setLocationRelativeTo(null);
|
||||
setVisible(true);
|
||||
}
|
||||
});
|
||||
|
||||
Robot robot = new Robot();
|
||||
robot.waitForIdle();
|
||||
|
||||
SwingUtilities.invokeAndWait(new Runnable() {
|
||||
public void run() {
|
||||
HTMLDocument doc = (HTMLDocument) editorPane.getDocument();
|
||||
doc.dump(System.out);
|
||||
goldenElement.checkStructureEquivalence((AbstractElement) doc.getDefaultRootElement());
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
|
||||
System.out.println();
|
||||
System.out.println("*********************************");
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
String dirURL = getDirURL();
|
||||
|
||||
System.out.println("dirURL = " + dirURL);
|
||||
|
||||
new bug7165725().execute(dirURL + "successive-script-tag.html", createSuccessiveScriptTags());
|
||||
new bug7165725().execute(dirURL + "false-text-after-script.html", createFalseTextAfterScript());
|
||||
|
||||
checkByCallbackForSuccessiveScript();
|
||||
checkByCallbackForFalseTextAfterScript();
|
||||
|
||||
System.out.println();
|
||||
System.out.println();
|
||||
System.out.println("Test passed.");
|
||||
}
|
||||
|
||||
static String getDirURL() {
|
||||
return "file:///" +
|
||||
new File(System.getProperty("test.src", ".")).getAbsolutePath() +
|
||||
File.separator;
|
||||
}
|
||||
|
||||
static String getParsedContentOneLine(String path) throws Exception {
|
||||
File f = new File(path);
|
||||
FileReader fr = new FileReader(f);
|
||||
ParserDelegator pd = new ParserDelegator();
|
||||
SBParserCallback sbcallback = new SBParserCallback();
|
||||
pd.parse(fr, sbcallback, true);
|
||||
fr.close();
|
||||
return sbcallback.getStringOneLine();
|
||||
}
|
||||
|
||||
static String getParsedContentOneLine(URL url) throws Exception {
|
||||
return getParsedContentOneLine(url.getPath());
|
||||
}
|
||||
|
||||
static void checkByCallbackForSuccessiveScript() throws Exception {
|
||||
String content = getParsedContentOneLine(new URL(getDirURL() + "successive-script-tag.html"));
|
||||
if (!content.matches(".*<script .*/js/js1\\.js.*<script .*/js/js2\\.js.*<script .*/js/js3\\.js.*"))
|
||||
throw new RuntimeException("Failed to lookup script tags/attributes.");
|
||||
if (!content.matches(".*<style .*stylesheets/base\\.css.*<style .*stylesheets/adv\\.css.*"))
|
||||
throw new RuntimeException("Failed to lookup style tags.");
|
||||
}
|
||||
|
||||
static void checkByCallbackForFalseTextAfterScript() throws Exception {
|
||||
String content = getParsedContentOneLine(new URL(getDirURL() + "false-text-after-script.html"));
|
||||
final int bodyIdx = content.indexOf("<body ");
|
||||
if (bodyIdx > 0) {
|
||||
String sbody = content.substring(bodyIdx);
|
||||
// There should be no Text(...) in this html
|
||||
if (sbody.indexOf("Text(") >= 0)
|
||||
throw new RuntimeException("Unexpected text found.");
|
||||
} else {
|
||||
throw new RuntimeException("Failed to find body tag.");
|
||||
}
|
||||
}
|
||||
|
||||
private static GoldenElement createSuccessiveScriptTags() {
|
||||
return new GoldenElement("html",
|
||||
new GoldenElement("head",
|
||||
new GoldenElement("p-implied",
|
||||
new GoldenElement("title"),
|
||||
new GoldenElement("title"),
|
||||
new GoldenElement("script"),
|
||||
new GoldenElement("comment"),
|
||||
new GoldenElement("script"),
|
||||
new GoldenElement("script"),
|
||||
new GoldenElement("comment"),
|
||||
new GoldenElement("script"),
|
||||
new GoldenElement("script"),
|
||||
new GoldenElement("comment"),
|
||||
new GoldenElement("script"),
|
||||
new GoldenElement("content"))),
|
||||
new GoldenElement("body",
|
||||
new GoldenElement("p-implied",
|
||||
new GoldenElement("content"))));
|
||||
}
|
||||
|
||||
private static GoldenElement createFalseTextAfterScript() {
|
||||
return new GoldenElement("html",
|
||||
new GoldenElement("head",
|
||||
new GoldenElement("p-implied",
|
||||
new GoldenElement("title"),
|
||||
new GoldenElement("title"),
|
||||
new GoldenElement("content"))),
|
||||
new GoldenElement("body",
|
||||
new GoldenElement("form",
|
||||
new GoldenElement("p-implied",
|
||||
new GoldenElement("input"),
|
||||
new GoldenElement("input"),
|
||||
new GoldenElement("content"))),
|
||||
new GoldenElement("p-implied",
|
||||
new GoldenElement("script"),
|
||||
new GoldenElement("comment"),
|
||||
new GoldenElement("script"),
|
||||
new GoldenElement("script"),
|
||||
new GoldenElement("comment"),
|
||||
new GoldenElement("script"),
|
||||
new GoldenElement("content"))));
|
||||
}
|
||||
|
||||
static class SBParserCallback extends HTMLEditorKit.ParserCallback
|
||||
{
|
||||
private int indentSize = 0;
|
||||
private ArrayList<String> elist = new ArrayList<>();
|
||||
|
||||
public String getStringOneLine() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String s : elist) sb.append(s);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (String s : elist) sb.append(s + "\n");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
protected void indent() {
|
||||
indentSize += 3;
|
||||
}
|
||||
protected void unIndent() {
|
||||
indentSize -= 3; if (indentSize < 0) indentSize = 0;
|
||||
}
|
||||
|
||||
protected String pIndent() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for(int i = 0; i < indentSize; i++) sb.append(" ");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public void handleText(char[] data, int pos) {
|
||||
elist.add(pIndent() + "Text(" + data.length + " chars) \"" + new String(data) + "\"");
|
||||
}
|
||||
|
||||
public void handleComment(char[] data, int pos) {
|
||||
elist.add(pIndent() + "Comment(" + data.length + " chars)");
|
||||
}
|
||||
|
||||
public void handleStartTag(HTML.Tag t, MutableAttributeSet a, int pos) {
|
||||
elist.add(pIndent() + "Tag start(<" + t.toString() + " " + a + ">, " +
|
||||
a.getAttributeCount() + " attrs)");
|
||||
indent();
|
||||
}
|
||||
|
||||
public void handleEndTag(HTML.Tag t, int pos) {
|
||||
unIndent();
|
||||
elist.add(pIndent() + "Tag end(</" + t.toString() + ">)");
|
||||
}
|
||||
|
||||
public void handleSimpleTag(HTML.Tag t, MutableAttributeSet a, int pos) {
|
||||
elist.add(pIndent() + "Tag(<" + t.toString() + ">, " +
|
||||
a.getAttributeCount() + " attrs)");
|
||||
}
|
||||
|
||||
public void handleError(String errorMsg, int pos){
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
<html>
|
||||
<head> <title> Testing </title> </head>
|
||||
<body>
|
||||
<form>
|
||||
|
||||
<input type="text" name="text1" >
|
||||
<input type="button" name="button1" value="button" onclick="test1(this.form)">
|
||||
|
||||
</form>
|
||||
|
||||
<SCRIPT LANGUAGE="JavaScript">
|
||||
function test1(form) {
|
||||
alert(form.text1.value);
|
||||
}
|
||||
</SCRIPT>
|
||||
<SCRIPT>
|
||||
history.forward();
|
||||
</SCRIPT>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<html>
|
||||
<head><title>my title</title>
|
||||
<script src="../../js/js1.js" language="JavaScript"></script><script src="../../js/js2.js" language="JavaScript"></script><script src="../../js/js3.js" language="JavaScript"></script><style type="text/css" media="screen">@import "stylesheets/base.css";</style><style type="text/css" media="screen">@import "stylesheets/adv.css";</style>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8028616
|
||||
* @summary Tests correct parsing of the text with leading slash (/)
|
||||
* @author Dmitry Markov
|
||||
*/
|
||||
|
||||
import javax.swing.text.html.HTMLDocument;
|
||||
import javax.swing.text.html.HTMLEditorKit;
|
||||
import java.io.StringReader;
|
||||
|
||||
public class bug8028616 {
|
||||
private static final String text = "/ at start is bad";
|
||||
private static Object lock = new Object();
|
||||
private static boolean isCallbackInvoked = false;
|
||||
private static Exception exception = null;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
ParserCB cb = new ParserCB();
|
||||
HTMLEditorKit htmlKit = new HTMLEditorKit();
|
||||
HTMLDocument htmlDoc = (HTMLDocument) htmlKit.createDefaultDocument();
|
||||
|
||||
htmlDoc.getParser().parse(new StringReader(text), cb, true);
|
||||
|
||||
synchronized (lock) {
|
||||
if (!isCallbackInvoked) {
|
||||
lock.wait(5000);
|
||||
}
|
||||
}
|
||||
|
||||
if (!isCallbackInvoked) {
|
||||
throw new RuntimeException("Test Failed: ParserCallback.handleText() is not invoked for text - " + text);
|
||||
}
|
||||
|
||||
if (exception != null) {
|
||||
throw exception;
|
||||
}
|
||||
}
|
||||
|
||||
private static class ParserCB extends HTMLEditorKit.ParserCallback {
|
||||
@Override
|
||||
public void handleText(char[] data, int pos) {
|
||||
synchronized (lock) {
|
||||
if (!text.equals(new String(data)) || pos != 0) {
|
||||
exception = new RuntimeException(
|
||||
"Test Failed: the data passed to ParserCallback.handleText() does not meet the expectation");
|
||||
}
|
||||
isCallbackInvoked = true;
|
||||
lock.notifyAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* Copyright (c) 2016, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.text.Document;
|
||||
import javax.swing.text.html.HTMLEditorKit;
|
||||
|
||||
import jdk.test.lib.Utils;
|
||||
|
||||
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||
|
||||
/* @test
|
||||
@bug 8078268
|
||||
@summary javax.swing.text.html.parser.Parser parseScript incorrectly optimized
|
||||
@library /test/lib
|
||||
@run main bug8078268
|
||||
*/
|
||||
public class bug8078268 {
|
||||
private static final long TIMEOUT = (long) (10_000 * Utils.TIMEOUT_FACTOR);
|
||||
|
||||
private static final String FILENAME = "slowparse.html";
|
||||
|
||||
private static final CountDownLatch latch = new CountDownLatch(1);
|
||||
private static volatile Exception exception;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
HTMLEditorKit htmlKit = new HTMLEditorKit();
|
||||
Document doc = htmlKit.createDefaultDocument();
|
||||
try {
|
||||
htmlKit.read(new FileReader(getAbsolutePath()), doc, 0);
|
||||
} catch (Exception e) {
|
||||
exception = e;
|
||||
}
|
||||
latch.countDown();
|
||||
}
|
||||
});
|
||||
|
||||
if (!latch.await(TIMEOUT, MILLISECONDS)) {
|
||||
throw new RuntimeException("Parsing takes too long. Current timeout is " + TIMEOUT);
|
||||
}
|
||||
if (exception != null) {
|
||||
throw exception;
|
||||
}
|
||||
}
|
||||
|
||||
private static String getAbsolutePath() {
|
||||
return System.getProperty("test.src", ".")
|
||||
+ File.separator + FILENAME;
|
||||
}
|
||||
}
|
||||
3539
test/jdk/javax/swing/text/html/parser/Parser/8078268/slowparse.html
Normal file
3539
test/jdk/javax/swing/text/html/parser/Parser/8078268/slowparse.html
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.text.MutableAttributeSet;
|
||||
import javax.swing.text.html.HTML;
|
||||
import javax.swing.text.html.HTMLDocument;
|
||||
import javax.swing.text.html.HTMLEditorKit;
|
||||
import java.io.*;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
/* @test
|
||||
@bug 8177450
|
||||
@summary javax.swing.text.html.parser.Parser parseScript ignores a character after commend end
|
||||
@author Mikhail Cherkasov
|
||||
@run main HtmlCommentTagParseTest
|
||||
*/
|
||||
public class HtmlCommentTagParseTest {
|
||||
private static volatile boolean failed = false;
|
||||
public static void main(String[] args) throws IOException, InvocationTargetException, InterruptedException {
|
||||
SwingUtilities.invokeAndWait(() -> {
|
||||
MyParser cb = new MyParser();
|
||||
HTMLEditorKit htmlKit = new HTMLEditorKit();
|
||||
HTMLDocument htmlDoc = (HTMLDocument)
|
||||
htmlKit.createDefaultDocument();
|
||||
FileReader reader = null;
|
||||
try {
|
||||
reader = new FileReader(getDirURL() + "test.html");
|
||||
htmlDoc.getParser().parse(reader, cb, true);
|
||||
if(failed) {
|
||||
throw new RuntimeException("Test failed");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
private static String getDirURL() {
|
||||
return new File(System.getProperty("test.src", ".")).getAbsolutePath() +
|
||||
File.separator;
|
||||
}
|
||||
|
||||
private static class MyParser extends HTMLEditorKit.ParserCallback {
|
||||
@Override
|
||||
public void handleError(String errorMsg, int pos) {
|
||||
failed = errorMsg.contains("eof.script");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
<html>
|
||||
<body>
|
||||
<script><!-- --></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* @test
|
||||
* @bug 7172359
|
||||
* @summary Verifies HTML parser StackOverflowError on invalid HTML: <li> tag
|
||||
* inside an <option>
|
||||
* @run main ParserStackOverflow
|
||||
*/
|
||||
import javax.swing.text.html.HTMLDocument;
|
||||
import javax.swing.text.html.HTMLEditorKit;
|
||||
import java.io.StringReader;
|
||||
import java.io.Reader;
|
||||
|
||||
public class ParserStackOverflow {
|
||||
/*
|
||||
* li element inside an option will crash javax.swing.text.html.parser.Parser
|
||||
*/
|
||||
public static void main( String[] argv ) throws Exception {
|
||||
String badHtml =
|
||||
"<html><body><form><select><option><li></option></select></form></body></html>";
|
||||
|
||||
HTMLEditorKit kit = new HTMLEditorKit();
|
||||
HTMLDocument doc = (HTMLDocument) kit.createDefaultDocument();
|
||||
Reader reader = new StringReader(badHtml);
|
||||
kit.read(reader, doc, 0); // StackOverflowError here
|
||||
|
||||
System.out.println("Succeeded! (no StackOverflowError)");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* @test
|
||||
* @bug 8296660
|
||||
* @library /java/awt/regtesthelpers
|
||||
* @build PassFailJFrame
|
||||
* @summary Verifies Swing HTML table with omitted closing tags parsed correctly
|
||||
* @run main/manual TestHtmlOptionalClosingTag
|
||||
*/
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
public class TestHtmlOptionalClosingTag {
|
||||
|
||||
private static JFrame frame;
|
||||
|
||||
private static final String INSTRUCTIONS =
|
||||
" A Swing JLabel with a two-column HTML table is shown\n " +
|
||||
" If the table is shown without any alignment issue\n " +
|
||||
" then press Pass, otherwise test fails";
|
||||
|
||||
public static void createAndShowGUI() {
|
||||
frame = new JFrame();
|
||||
String html = "<html><table>" +
|
||||
"<tr><th align=right>Name:<td>sync-001.mp4" +
|
||||
"<tr><th align=right>Modified:<td>2017-Jul-31, 00:14:55" +
|
||||
"<tr><th align=right>File size:<td>3.1 MB" +
|
||||
"<tr><th align=right>Duration:<td>1m03s" +
|
||||
"<tr><th align=right>Video:<td>854 x 480 - 16:9 - 30.0 fps - 271 kbps - H.264 / AVC" +
|
||||
"<tr><th align=right>Audio:<td>Stereo - 44100 Hz - 123 kbps - AAC";
|
||||
|
||||
JLabel label = new JLabel(html);
|
||||
frame.add(label);
|
||||
frame.setSize(400, 400);
|
||||
frame.setLocationRelativeTo(null);
|
||||
frame.setVisible(true);
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] argv) throws Exception {
|
||||
PassFailJFrame passFailJFrame = new PassFailJFrame(
|
||||
"SwingHtmlTable Test", INSTRUCTIONS, 5);
|
||||
SwingUtilities.invokeAndWait(() -> createAndShowGUI());
|
||||
PassFailJFrame.addTestWindow(frame);
|
||||
PassFailJFrame.positionTestWindow(
|
||||
frame, PassFailJFrame.Position.HORIZONTAL);
|
||||
passFailJFrame.awaitAndCheck();
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue