Skip to content

Commit a6ebf14

Browse files
committed
Mozilla bug 1562033. r=alchen.
1 parent 8f9f6bc commit a6ebf14

File tree

2 files changed

+36
-18
lines changed

2 files changed

+36
-18
lines changed

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

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -745,13 +745,30 @@ public void setHtml4ModeCompatibleWithXhtml1Schemata(
745745
// ]NOCPP]
746746

747747
// For the token handler to call
748+
748749
/**
749750
* Sets the tokenizer state and the associated element name. This should
750751
* only ever used to put the tokenizer into one of the states that have
751752
* a special end tag expectation.
752753
*
753754
* @param specialTokenizerState
754755
* the tokenizer state to set
756+
*/
757+
public void setState(int specialTokenizerState) {
758+
this.stateSave = specialTokenizerState;
759+
this.endTagExpectation = null;
760+
this.endTagExpectationAsArray = null;
761+
}
762+
763+
// [NOCPP[
764+
765+
/**
766+
* Sets the tokenizer state and the associated element name. This should
767+
* only ever used to put the tokenizer into one of the states that have
768+
* a special end tag expectation. For use from the tokenizer test harness.
769+
*
770+
* @param specialTokenizerState
771+
* the tokenizer state to set
755772
* @param endTagExpectation
756773
* the expected end tag for transitioning back to normal
757774
*/
@@ -768,6 +785,8 @@ public void setStateAndEndTagExpectation(int specialTokenizerState,
768785
endTagExpectationToArray();
769786
}
770787

788+
// ]NOCPP]
789+
771790
/**
772791
* Sets the tokenizer state and the associated element name. This should
773792
* only ever used to put the tokenizer into one of the states that have
@@ -3858,11 +3877,17 @@ private void ensureBufferSpace(int inputLength) throws SAXException {
38583877
c = checkChar(buf, pos);
38593878
/*
38603879
* ASSERT! when entering this state, set index to 0 and
3861-
* call clearStrBufBeforeUse() assert (contentModelElement !=
3862-
* null); Let's implement the above without lookahead.
3863-
* strBuf is the 'temporary buffer'.
3880+
* call clearStrBufBeforeUse(); Let's implement the above
3881+
* without lookahead. strBuf is the 'temporary buffer'.
38643882
*/
3865-
if (index < endTagExpectationAsArray.length) {
3883+
if (endTagExpectationAsArray == null) {
3884+
tokenHandler.characters(Tokenizer.LT_SOLIDUS,
3885+
0, 2);
3886+
cstart = pos;
3887+
reconsume = true;
3888+
state = transition(state, returnState, reconsume, pos);
3889+
continue stateloop;
3890+
} else if (index < endTagExpectationAsArray.length) {
38663891
char e = endTagExpectationAsArray[index];
38673892
char folded = c;
38683893
if (c >= 'A' && c <= 'Z') {

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

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -656,8 +656,7 @@ final void warn(String message, Locator locator) throws SAXException {
656656
);
657657
currentPtr++;
658658
stack[currentPtr] = node;
659-
tokenizer.setStateAndEndTagExpectation(Tokenizer.DATA,
660-
contextName);
659+
tokenizer.setState(Tokenizer.DATA);
661660
// The frameset-ok flag is set even though <frameset> never
662661
// ends up being allowed as HTML frameset in the fragment case.
663662
mode = FRAMESET_OK;
@@ -687,8 +686,7 @@ final void warn(String message, Locator locator) throws SAXException {
687686
);
688687
currentPtr++;
689688
stack[currentPtr] = node;
690-
tokenizer.setStateAndEndTagExpectation(Tokenizer.DATA,
691-
contextName);
689+
tokenizer.setState(Tokenizer.DATA);
692690
// The frameset-ok flag is set even though <frameset> never
693691
// ends up being allowed as HTML frameset in the fragment case.
694692
mode = FRAMESET_OK;
@@ -707,23 +705,18 @@ final void warn(String message, Locator locator) throws SAXException {
707705
resetTheInsertionMode();
708706
formPointer = getFormPointerForContext(contextNode);
709707
if ("title" == contextName || "textarea" == contextName) {
710-
tokenizer.setStateAndEndTagExpectation(Tokenizer.RCDATA,
711-
contextName);
708+
tokenizer.setState(Tokenizer.RCDATA);
712709
} else if ("style" == contextName || "xmp" == contextName
713710
|| "iframe" == contextName || "noembed" == contextName
714711
|| "noframes" == contextName
715712
|| (scriptingEnabled && "noscript" == contextName)) {
716-
tokenizer.setStateAndEndTagExpectation(Tokenizer.RAWTEXT,
717-
contextName);
713+
tokenizer.setState(Tokenizer.RAWTEXT);
718714
} else if ("plaintext" == contextName) {
719-
tokenizer.setStateAndEndTagExpectation(Tokenizer.PLAINTEXT,
720-
contextName);
715+
tokenizer.setState(Tokenizer.PLAINTEXT);
721716
} else if ("script" == contextName) {
722-
tokenizer.setStateAndEndTagExpectation(
723-
Tokenizer.SCRIPT_DATA, contextName);
717+
tokenizer.setState(Tokenizer.SCRIPT_DATA);
724718
} else {
725-
tokenizer.setStateAndEndTagExpectation(Tokenizer.DATA,
726-
contextName);
719+
tokenizer.setState(Tokenizer.DATA);
727720
}
728721
}
729722
contextName = null;

0 commit comments

Comments
 (0)