Skip to content

Commit 53c7bbf

Browse files
committed
Mozilla bug 1540675 - Handle line breaks correctly in comment end bang state. r=alchen.
1 parent 76acd04 commit 53c7bbf

File tree

5 files changed

+41
-4
lines changed

5 files changed

+41
-4
lines changed

src/nu/validator/htmlparser/impl/Tokenizer.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2820,10 +2820,12 @@ private void ensureBufferSpace(int inputLength) throws SAXException {
28202820
continue stateloop;
28212821
case '\r':
28222822
appendStrBufCarriageReturn();
2823+
state = transition(state, Tokenizer.COMMENT, reconsume, pos);
28232824
break stateloop;
28242825
case '\n':
28252826
appendStrBufLineFeed();
2826-
continue;
2827+
state = transition(state, Tokenizer.COMMENT, reconsume, pos);
2828+
continue stateloop;
28272829
case '\u0000':
28282830
c = '\uFFFD';
28292831
// CPPONLY: MOZ_FALLTHROUGH;

src/nu/validator/htmlparser/impl/TreeBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5231,7 +5231,7 @@ private void popForeign(int origPos, int eltPos) throws SAXException {
52315231
StackNode<T> node = stack[currentPtr];
52325232
if (origPos != currentPtr || eltPos != currentPtr) {
52335233
markMalformedIfScript(node.node);
5234-
}
5234+
}
52355235
assert debugOnlyClearLastStackSlot();
52365236
currentPtr--;
52375237
elementPopped(node.ns, node.popName, node.node);

test-src/nu/validator/htmlparser/test/JSONArrayTokenHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ public boolean wantsComments() throws SAXException {
145145
}
146146

147147
public void error(SAXParseException exception) throws SAXException {
148-
flushCharacters();
149-
array.getValue().add(PARSE_ERROR);
148+
// flushCharacters();
149+
// array.getValue().add(PARSE_ERROR);
150150
}
151151

152152
public void fatalError(SAXParseException exception) throws SAXException {

test-src/nu/validator/htmlparser/test/TokenizerTester.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,12 @@ public class TokenizerTester {
5757

5858
private static JSONString RCDATA = new JSONString("RCDATA state");
5959

60+
private static JSONString CDATA = new JSONString("CDATA section state");
61+
6062
private static JSONString RAWTEXT = new JSONString("RAWTEXT state");
6163

64+
private static JSONString SCRIPT_DATA = new JSONString("Script data state");
65+
6266
private static boolean jsonDeepEquals(JSONValue one, JSONValue other) {
6367
if (one.isSimple()) {
6468
return one.equals(other);
@@ -144,9 +148,15 @@ private void runTest(JSONObject test) throws SAXException, IOException {
144148
} else if (RCDATA.equals(value)) {
145149
runTestInner(inputString, expectedTokens, description,
146150
Tokenizer.RCDATA, lastStartTag);
151+
} else if (CDATA.equals(value)) {
152+
runTestInner(inputString, expectedTokens, description,
153+
Tokenizer.CDATA_SECTION, lastStartTag);
147154
} else if (PLAINTEXT.equals(value)) {
148155
runTestInner(inputString, expectedTokens, description,
149156
Tokenizer.PLAINTEXT, lastStartTag);
157+
} else if (SCRIPT_DATA.equals(value)) {
158+
runTestInner(inputString, expectedTokens, description,
159+
Tokenizer.SCRIPT_DATA, "script");
150160
} else {
151161
throw new RuntimeException("Broken test data.");
152162
}

test-src/nu/validator/htmlparser/test/TreeTester.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,25 @@ private boolean runTest() throws Throwable {
8383
// spin
8484
}
8585

86+
boolean newErrors = false;
8687
StringBuilder sb = new StringBuilder();
8788
int c;
8889
while ((c = aggregateStream.read()) != '\n') {
8990
sb.append((char) c);
9091
}
9192
String label = sb.toString();
93+
if ("new-errors".equals(label)) {
94+
newErrors = true;
95+
stream = new UntilHashInputStream(aggregateStream);
96+
while (stream.read() != -1) {
97+
// spin
98+
}
99+
sb.setLength(0);
100+
while ((c = aggregateStream.read()) != '\n') {
101+
sb.append((char) c);
102+
}
103+
label = sb.toString();
104+
}
92105
if ("document-fragment".equals(label)) {
93106
sb.setLength(0);
94107
while ((c = aggregateStream.read()) != '\n') {
@@ -160,6 +173,18 @@ private boolean runTest() throws Throwable {
160173
expectedErrors.add(line);
161174
}
162175

176+
if (newErrors) {
177+
if (skipLabel()) { // #new-errors
178+
System.err.println("Premature end of test data.");
179+
return false;
180+
}
181+
br = new BufferedReader(new InputStreamReader(
182+
new UntilHashInputStream(aggregateStream), "UTF-8"));
183+
while ((line = br.readLine()) != null) {
184+
expectedErrors.add(line);
185+
}
186+
}
187+
163188
if (context != null) {
164189
if (skipLabel()) { // #document-fragment
165190
System.err.println("Premature end of test data.");

0 commit comments

Comments
 (0)