changeset 11666:4c27305cae8b

8078268: javax.swing.text.html.parser.Parser parseScript incorrectly optimized Reviewed-by: alexp, aivanov
author mcherkas
date Fri, 13 May 2016 16:46:54 +0300
parents efd9e219a5bd
children a5d597f09c9d
files src/share/classes/javax/swing/text/html/parser/Parser.java test/javax/swing/text/html/parser/Parser/8078268/bug8078268.java test/javax/swing/text/html/parser/Parser/8078268/slowparse.html
diffstat 1 files changed, 55 insertions(+), 43 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/javax/swing/text/html/parser/Parser.java	Fri May 13 16:36:39 2016 +0300
+++ b/src/share/classes/javax/swing/text/html/parser/Parser.java	Fri May 13 16:46:54 2016 +0300
@@ -1986,57 +1986,69 @@
         while (true) {
             int i = 0;
             while (!insideComment && i < SCRIPT_END_TAG.length
-                       && (SCRIPT_END_TAG[i] == ch
-                           || SCRIPT_END_TAG_UPPER_CASE[i] == ch)) {
+                    && (SCRIPT_END_TAG[i] == ch
+                    || SCRIPT_END_TAG_UPPER_CASE[i] == ch)) {
                 charsToAdd[i] = (char) ch;
                 ch = readCh();
                 i++;
             }
             if (i == SCRIPT_END_TAG.length) {
+                return;
+            }
 
-                /*  '</script>' tag detected */
-                /* Here, ch == the first character after </script> */
+            if (!insideComment && i == 1 && charsToAdd[0] == START_COMMENT.charAt(0)) {
+                // it isn't end script tag, but may be it's start comment tag?
+                while (i < START_COMMENT.length()
+                        && START_COMMENT.charAt(i) == ch) {
+                    charsToAdd[i] = (char) ch;
+                    ch = readCh();
+                    i++;
+                }
+                if (i == START_COMMENT.length()) {
+                    insideComment = true;
+                }
+            }
+            if (insideComment) {
+                while (i < END_COMMENT.length()
+                        && END_COMMENT.charAt(i) == ch) {
+                    charsToAdd[i] = (char) ch;
+                    ch = readCh();
+                    i++;
+                }
+                if (i == END_COMMENT.length()) {
+                    insideComment = false;
+                }
+            }
+
+            /* To account for extra read()'s that happened */
+            for (int j = 0; j < i; j++) {
+                addString(charsToAdd[j]);
+            }
+            switch (ch) {
+            case -1:
+                error("eof.script");
                 return;
-            } else {
-
-                /* To account for extra read()'s that happened */
-                for (int j = 0; j < i; j++) {
-                    addString(charsToAdd[j]);
+            case '\n':
+                ln++;
+                ch = readCh();
+                lfCount++;
+                addString('\n');
+                break;
+            case '\r':
+                ln++;
+                if ((ch = readCh()) == '\n') {
+                    ch = readCh();
+                    crlfCount++;
+                } else {
+                    crCount++;
                 }
-
-                switch (ch) {
-                case -1:
-                    error("eof.script");
-                    return;
-                case '\n':
-                    ln++;
-                    ch = readCh();
-                    lfCount++;
-                    addString('\n');
-                    break;
-                case '\r':
-                    ln++;
-                    if ((ch = readCh()) == '\n') {
-                        ch = readCh();
-                        crlfCount++;
-                    } else {
-                        crCount++;
-                    }
-                    addString('\n');
-                    break;
-                default:
-                    addString(ch);
-                    String str = new String(getChars(0, strpos));
-                    if (!insideComment && str.endsWith(START_COMMENT)) {
-                        insideComment = true;
-                    }
-                    if (insideComment && str.endsWith(END_COMMENT)) {
-                        insideComment = false;
-                    }
-                    ch = readCh();
-                    break;
-                } // switch
-            }
+                addString('\n');
+                break;
+            default:
+                addString(ch);
+                ch = readCh();
+                break;
+            } // switch
         } // while
     }