author | mcherkas |
Tue, 21 May 2013 03:20:27 +0400 | |
changeset 17678 | ec24ad8455ec |
permissions | -rw-r--r-- |
17678
ec24ad8455ec
7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents:
diff
changeset
|
1 |
/* |
ec24ad8455ec
7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents:
diff
changeset
|
2 |
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. |
ec24ad8455ec
7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ec24ad8455ec
7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents:
diff
changeset
|
4 |
* |
ec24ad8455ec
7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
ec24ad8455ec
7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
ec24ad8455ec
7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
ec24ad8455ec
7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents:
diff
changeset
|
8 |
* |
ec24ad8455ec
7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
ec24ad8455ec
7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ec24ad8455ec
7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ec24ad8455ec
7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
ec24ad8455ec
7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents:
diff
changeset
|
13 |
* accompanied this code). |
ec24ad8455ec
7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents:
diff
changeset
|
14 |
* |
ec24ad8455ec
7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
ec24ad8455ec
7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
ec24ad8455ec
7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ec24ad8455ec
7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents:
diff
changeset
|
18 |
* |
ec24ad8455ec
7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ec24ad8455ec
7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
ec24ad8455ec
7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents:
diff
changeset
|
21 |
* questions. |
ec24ad8455ec
7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents:
diff
changeset
|
22 |
*/ |
ec24ad8455ec
7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents:
diff
changeset
|
23 |
|
ec24ad8455ec
7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents:
diff
changeset
|
24 |
/* |
ec24ad8455ec
7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents:
diff
changeset
|
25 |
* @test |
ec24ad8455ec
7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents:
diff
changeset
|
26 |
* @bug 7011777 |
ec24ad8455ec
7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents:
diff
changeset
|
27 |
* @summary Tests correct parsing of a HTML comment inside 'script' tags |
ec24ad8455ec
7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents:
diff
changeset
|
28 |
* @author Dmitry Markov |
ec24ad8455ec
7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents:
diff
changeset
|
29 |
*/ |
ec24ad8455ec
7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents:
diff
changeset
|
30 |
|
ec24ad8455ec
7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents:
diff
changeset
|
31 |
import javax.swing.text.html.HTMLEditorKit; |
ec24ad8455ec
7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents:
diff
changeset
|
32 |
import javax.swing.text.html.parser.ParserDelegator; |
ec24ad8455ec
7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents:
diff
changeset
|
33 |
import java.io.StringReader; |
ec24ad8455ec
7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents:
diff
changeset
|
34 |
|
ec24ad8455ec
7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents:
diff
changeset
|
35 |
public class bug7011777 { |
ec24ad8455ec
7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents:
diff
changeset
|
36 |
static String comment = "<!--\n" + |
ec24ad8455ec
7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents:
diff
changeset
|
37 |
"function foo() {\n" + |
ec24ad8455ec
7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents:
diff
changeset
|
38 |
" var tag1 = \"</script>\";\n" + |
ec24ad8455ec
7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents:
diff
changeset
|
39 |
" var tag2 = \"<div>\";\n" + |
ec24ad8455ec
7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents:
diff
changeset
|
40 |
" var tag3 = \"</div>\";\n" + |
ec24ad8455ec
7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents:
diff
changeset
|
41 |
" var tag4 = \"<script>\";\n" + |
ec24ad8455ec
7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents:
diff
changeset
|
42 |
"}\n" + |
ec24ad8455ec
7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents:
diff
changeset
|
43 |
"// -->"; |
ec24ad8455ec
7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents:
diff
changeset
|
44 |
static String html = "<script>" + comment + "</script>"; |
ec24ad8455ec
7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents:
diff
changeset
|
45 |
public static void main(String[] args) throws Exception { |
ec24ad8455ec
7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents:
diff
changeset
|
46 |
new ParserDelegator().parse(new StringReader(html), new MyParserCallback(), true); |
ec24ad8455ec
7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents:
diff
changeset
|
47 |
} |
ec24ad8455ec
7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents:
diff
changeset
|
48 |
|
ec24ad8455ec
7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents:
diff
changeset
|
49 |
static class MyParserCallback extends HTMLEditorKit.ParserCallback { |
ec24ad8455ec
7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents:
diff
changeset
|
50 |
|
ec24ad8455ec
7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents:
diff
changeset
|
51 |
@Override |
ec24ad8455ec
7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents:
diff
changeset
|
52 |
public void handleComment(char[] data, int pos) { |
ec24ad8455ec
7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents:
diff
changeset
|
53 |
String commentWithoutTags = comment.substring("<!--".length(), comment.length() - "-->".length()); |
ec24ad8455ec
7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents:
diff
changeset
|
54 |
String str = new String(data); |
ec24ad8455ec
7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents:
diff
changeset
|
55 |
if (!commentWithoutTags.equals(str)) { |
ec24ad8455ec
7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents:
diff
changeset
|
56 |
System.out.println("Sample string:\n" + commentWithoutTags); |
ec24ad8455ec
7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents:
diff
changeset
|
57 |
System.out.println("Returned string:\n" + str); |
ec24ad8455ec
7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents:
diff
changeset
|
58 |
throw new RuntimeException("Test Failed, sample and returned strings are mismatched!"); |
ec24ad8455ec
7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents:
diff
changeset
|
59 |
} |
ec24ad8455ec
7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents:
diff
changeset
|
60 |
} |
ec24ad8455ec
7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents:
diff
changeset
|
61 |
} |
ec24ad8455ec
7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents:
diff
changeset
|
62 |
|
ec24ad8455ec
7011777: JDK 6 parses html text with script tags within comments differently from previous releases
mcherkas
parents:
diff
changeset
|
63 |
} |