Bug 1540675 - Handle line breaks correctly in comment end bang state. r=alchen.
authorHenri Sivonen <hsivonen@hsivonen.fi>
Mon, 01 Apr 2019 15:06:08 +0300
changeset 469596 4aeaae90b1a1690a51a8272226b8c104a23a1084
parent 469595 03b7cf8b0c1838e421130f24ddb13d1aeee0a36e
child 469597 48f7c91bbdbf479e16c85a6b1e716daa2c06621c
push id35875
push userccoroiu@mozilla.com
push dateTue, 16 Apr 2019 04:06:16 +0000
treeherdermozilla-central@a83cab75b00d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersalchen
bugs1540675
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1540675 - Handle line breaks correctly in comment end bang state. r=alchen. Differential Revision: https://phabricator.services.mozilla.com/D25594
parser/html/javasrc/Tokenizer.java
parser/html/javasrc/TreeBuilder.java
parser/html/nsHtml5Tokenizer.cpp
parser/htmlparser/tests/mochitest/html5lib_tree_construction/comments01.dat
--- a/parser/html/javasrc/Tokenizer.java
+++ b/parser/html/javasrc/Tokenizer.java
@@ -2815,20 +2815,22 @@ public class Tokenizer implements Locato
                                 appendStrBuf(c);
                                 /*
                                  * Switch to the comment end dash state.
                                  */
                                 state = transition(state, Tokenizer.COMMENT_END_DASH, reconsume, pos);
                                 continue stateloop;
                             case '\r':
                                 appendStrBufCarriageReturn();
+                                state = transition(state, Tokenizer.COMMENT, reconsume, pos);
                                 break stateloop;
                             case '\n':
                                 appendStrBufLineFeed();
-                                continue;
+                                state = transition(state, Tokenizer.COMMENT, reconsume, pos);
+                                continue stateloop;
                             case '\u0000':
                                 c = '\uFFFD';
                                 // CPPONLY: MOZ_FALLTHROUGH;
                             default:
                                 /*
                                  * Anything else Append two U+002D HYPHEN-MINUS
                                  * (-) characters, a U+0021 EXCLAMATION MARK (!)
                                  * character, and the input character to the
--- a/parser/html/javasrc/TreeBuilder.java
+++ b/parser/html/javasrc/TreeBuilder.java
@@ -5226,17 +5226,17 @@ public abstract class TreeBuilder<T> imp
         elementPopped(node.ns, node.popName, node.node);
         node.release(this);
     }
 
     private void popForeign(int origPos, int eltPos) throws SAXException {
         StackNode<T> node = stack[currentPtr];
         if (origPos != currentPtr || eltPos != currentPtr) {
             markMalformedIfScript(node.node);
-            }
+        }
         assert debugOnlyClearLastStackSlot();
         currentPtr--;
         elementPopped(node.ns, node.popName, node.node);
         node.release(this);
     }
 
     private void silentPop() throws SAXException {
         StackNode<T> node = stack[currentPtr];
--- a/parser/html/nsHtml5Tokenizer.cpp
+++ b/parser/html/nsHtml5Tokenizer.cpp
@@ -1433,21 +1433,25 @@ stateloop:
               appendStrBuf(c);
               state =
                   P::transition(mViewSource, nsHtml5Tokenizer::COMMENT_END_DASH,
                                 reconsume, pos);
               NS_HTML5_CONTINUE(stateloop);
             }
             case '\r': {
               appendStrBufCarriageReturn();
+              state = P::transition(mViewSource, nsHtml5Tokenizer::COMMENT,
+                                    reconsume, pos);
               NS_HTML5_BREAK(stateloop);
             }
             case '\n': {
               appendStrBufLineFeed();
-              continue;
+              state = P::transition(mViewSource, nsHtml5Tokenizer::COMMENT,
+                                    reconsume, pos);
+              NS_HTML5_CONTINUE(stateloop);
             }
             case '\0': {
               c = 0xfffd;
               MOZ_FALLTHROUGH;
             }
             default: {
               appendStrBuf(c);
               state = P::transition(mViewSource, nsHtml5Tokenizer::COMMENT,
--- a/parser/htmlparser/tests/mochitest/html5lib_tree_construction/comments01.dat
+++ b/parser/htmlparser/tests/mochitest/html5lib_tree_construction/comments01.dat
@@ -19,16 +19,44 @@ FOO<!-- BAR --!>BAZ
 | <html>
 |   <head>
 |   <body>
 |     "FOO"
 |     <!--  BAR  -->
 |     "BAZ"
 
 #data
+FOO<!-- BAR --! >BAZ
+#errors
+(1,3): expected-doctype-but-got-chars
+#new-errors
+(1:20) eof-in-comment
+#document
+| <html>
+|   <head>
+|   <body>
+|     "FOO"
+|     <!--  BAR --! >BAZ -->
+
+#data
+FOO<!-- BAR --!
+>BAZ
+#errors
+(1,3): expected-doctype-but-got-chars
+#new-errors
+(1:20) eof-in-comment
+#document
+| <html>
+|   <head>
+|   <body>
+|     "FOO"
+|     <!--  BAR --!
+>BAZ -->
+
+#data
 FOO<!-- BAR --   >BAZ
 #errors
 (1,3): expected-doctype-but-got-chars
 (1,15): unexpected-char-in-comment
 (1,21): eof-in-comment
 #document
 | <html>
 |   <head>