bug 70918: view-source adds > to tags that are missing them. r=bzbarsky sr=dmose

This commit is contained in:
mrbkap%gmail.com 2004-10-17 03:03:46 +00:00
Родитель cc085ad3d0
Коммит 36c54fb6da
6 изменённых файлов: 67 добавлений и 31 удалений

Просмотреть файл

@ -264,6 +264,16 @@ class CToken {
mLineNumber = mLineNumber == 0 ? aLineNumber : mLineNumber;
}
void SetInError(PRBool aInError)
{
mInError = aInError;
}
PRBool IsInError()
{
return mInError;
}
void SetAttributeCount(PRInt16 aValue) { mAttrCount = aValue; }
/**
@ -285,7 +295,8 @@ protected:
PRInt32 mTypeID;
PRInt32 mUseCount;
PRInt32 mNewlineCount;
PRInt32 mLineNumber;
PRUint32 mLineNumber : 31;
PRUint32 mInError : 1;
PRInt16 mAttrCount;
};

Просмотреть файл

@ -688,12 +688,17 @@ nsresult nsHTMLTokenizer::ConsumeAttributes(PRUnichar aChar,
done = PR_TRUE;
}
else if(aChar == kLessThan) {
aToken->SetInError(PR_TRUE);
done = PR_TRUE;
}
}//if
}//if
}//while
if (NS_FAILED(result)) {
aToken->SetInError(PR_TRUE);
}
aToken->SetAttributeCount(theAttrCount);
return result;
}
@ -728,6 +733,9 @@ nsresult nsHTMLTokenizer::ConsumeStartTag(PRUnichar aChar,CToken*& aToken,nsScan
//Good. Now, let's see if the next char is ">".
//If so, we have a complete tag, otherwise, we have attributes.
result = aScanner.Peek(aChar);
if (NS_FAILED(result)) {
aToken->SetInError(PR_TRUE);
}
NS_ENSURE_SUCCESS(result, result);
if(kGreaterThan != aChar) { //look for '>'
@ -854,6 +862,9 @@ nsresult nsHTMLTokenizer::ConsumeEndTag(PRUnichar aChar,CToken*& aToken,nsScanne
NS_ENSURE_SUCCESS(result, result);
result = aScanner.Peek(aChar);
if (NS_FAILED(result)) {
aToken->SetInError(PR_TRUE);
}
NS_ENSURE_SUCCESS(result, result);
if(kGreaterThan != aChar) {

Просмотреть файл

@ -746,11 +746,6 @@ nsresult CCDATASectionToken::Consume(PRUnichar aChar, nsScanner& aScanner,PRInt3
if (NS_OK==result &&
(!inCDATA || kGreaterThan == aChar)) {
result=aScanner.GetChar(aChar); //strip off the >
// XXX take me out when view source isn't stupid anymore
if (aFlag & NS_IPARSER_FLAG_VIEW_SOURCE) {
mTextValue.Append(aChar);
}
done=PR_TRUE;
}
}
@ -763,8 +758,7 @@ nsresult CCDATASectionToken::Consume(PRUnichar aChar, nsScanner& aScanner,PRInt3
// In order to not completely lose the entire section, treat everything
// until the end of the document as part of the CDATA section and let
// the DTD handle it.
// XXX when view source actually displays errors, we'll need to propagate
// the EOF down to it (i.e., not do this if we're viewing source).
mInError = PR_TRUE;
result = NS_OK;
}
@ -896,6 +890,14 @@ nsresult CMarkupDeclToken::Consume(PRUnichar aChar, nsScanner& aScanner,PRInt32
aScanner.BindSubstring(mTextValue, origin, end);
if (kEOF == result) {
mInError = PR_TRUE;
if (!aScanner.IsIncremental()) {
// Hide this EOF.
result = NS_OK;
}
}
return result;
}
@ -1732,6 +1734,7 @@ nsresult CAttributeToken::Consume(PRUnichar aChar, nsScanner& aScanner,PRInt32 a
mTextValue.Append(aChar);
} else if (result == NS_ERROR_HTMLPARSER_UNTERMINATEDSTRINGLITERAL) {
result = NS_OK;
mInError = PR_TRUE;
}
// According to spec. we ( who? ) should ignore linefeeds. But look,
// even the carriage return was getting stripped ( wonder why! ) -
@ -1744,6 +1747,7 @@ nsresult CAttributeToken::Consume(PRUnichar aChar, nsScanner& aScanner,PRInt32 a
}
else if (kGreaterThan==aChar){
mHasEqualWithoutValue=PR_TRUE;
mInError=PR_TRUE;
}
else {
static const nsReadEndCondition
@ -1777,6 +1781,7 @@ nsresult CAttributeToken::Consume(PRUnichar aChar, nsScanner& aScanner,PRInt32 a
//so let's see what it is. If it's a '"', then assume we're reading
//from the middle of the value. Try stripping the quote and continuing...
if (kQuote==aChar || kApostrophe==aChar){
mInError=PR_TRUE;
if (!(aFlag & NS_IPARSER_FLAG_VIEW_SOURCE)) {
result=aScanner.SkipOver(aChar); //strip quote.
@ -2244,6 +2249,7 @@ nsresult CInstructionToken::Consume(PRUnichar aChar,nsScanner& aScanner,PRInt32
if (kEOF==result && !aScanner.IsIncremental()) {
//Hide the EOF result because there is no more text coming.
mInError=PR_TRUE;
result=NS_OK;
}
@ -2307,12 +2313,17 @@ nsresult CDoctypeDeclToken::Consume(PRUnichar aChar, nsScanner& aScanner,PRInt32
// could belong to another tag.
aScanner.GetChar(ch);
end.advance(1);
} else {
NS_ASSERTION(kLessThan == ch,
"Make sure this doctype decl. is really in error.");
mInError = PR_TRUE;
}
}
else if (!aScanner.IsIncremental()) {
// We have reached the document end but haven't
// found either a '<' or a '>'. Therefore use
// whatever we have.
mInError = PR_TRUE;
result = NS_OK;
}

Просмотреть файл

@ -69,6 +69,7 @@ CToken::CToken(PRInt32 aTag) {
mAttrCount=0;
mNewlineCount=0;
mLineNumber = 0;
mInError = PR_FALSE;
mTypeID=aTag;
// Note that the use count starts with 1 instead of 0. This
// is because of the assumption that any token created is in

Просмотреть файл

@ -978,7 +978,7 @@ nsresult CViewSourceHTML::WriteAttributes(PRInt32 attrCount) {
* @param
* @return result status
*/
nsresult CViewSourceHTML::WriteTag(PRInt32 aTagType,const nsAString & aText,PRInt32 attrCount,PRBool aNewlineRequired) {
nsresult CViewSourceHTML::WriteTag(PRInt32 aTagType,const nsAString & aText,PRInt32 attrCount,PRBool aTagInError) {
nsresult result=NS_OK;
// adjust line number to what it will be after we finish writing this tag
@ -997,9 +997,8 @@ nsresult CViewSourceHTML::WriteTag(PRInt32 aTagType,const nsAString & aText,PRIn
return NS_ERROR_FAILURE;
if (kBeforeText[aTagType][0] != 0) {
nsAutoString beforeText;
beforeText.AssignWithConversion(kBeforeText[aTagType]);
theContext.mITextToken.SetIndirectString(beforeText);
theContext.mITextToken.SetIndirectString(
NS_ConvertASCIItoUTF16(kBeforeText[aTagType]));
nsCParserNode theNode(&theContext.mITextToken, 0/*stack token*/);
mSink->AddLeaf(theNode);
}
@ -1052,15 +1051,16 @@ nsresult CViewSourceHTML::WriteTag(PRInt32 aTagType,const nsAString & aText,PRIn
result=WriteAttributes(attrCount);
}
if (kAfterText[aTagType][0] != 0) {
nsAutoString afterText;
afterText.AssignWithConversion(kAfterText[aTagType]);
theContext.mITextToken.SetIndirectString(afterText);
// Tokens are set in error if their ending > is not there, so don't output
// the after-text
if (!aTagInError && kAfterText[aTagType][0] != 0) {
theContext.mITextToken.SetIndirectString(
NS_ConvertASCIItoUTF16(kAfterText[aTagType]));
nsCParserNode theNode(&theContext.mITextToken, 0/*stack token*/);
mSink->AddLeaf(theNode);
}
#ifdef DUMP_TO_FILE
if (gDumpFile && kDumpFileAfterText[aTagType][0])
if (!aTagInError && gDumpFile && kDumpFileAfterText[aTagType][0])
fprintf(gDumpFile, kDumpFileAfterText[aTagType]);
#endif // DUMP_TO_FILE
@ -1097,7 +1097,7 @@ NS_IMETHODIMP CViewSourceHTML::HandleToken(CToken* aToken,nsIParser* aParser) {
++mTagCount;
const nsAString& startValue = aToken->GetStringValue();
result=WriteTag(mStartTag,startValue,aToken->GetAttributeCount(),PR_TRUE);
result=WriteTag(mStartTag,startValue,aToken->GetAttributeCount(),aToken->IsInError());
if((ePlainText!=mDocType) && mParser && (NS_OK==result)) {
result = mSink->NotifyTagObservers(&theContext.mTokenNode);
@ -1112,7 +1112,7 @@ NS_IMETHODIMP CViewSourceHTML::HandleToken(CToken* aToken,nsIParser* aParser) {
}
const nsAString& endValue = aToken->GetStringValue();
result=WriteTag(mEndTag,endValue,aToken->GetAttributeCount(),PR_TRUE);
result=WriteTag(mEndTag,endValue,aToken->GetAttributeCount(),aToken->IsInError());
}
break;
@ -1121,10 +1121,10 @@ NS_IMETHODIMP CViewSourceHTML::HandleToken(CToken* aToken,nsIParser* aParser) {
nsAutoString theStr;
theStr.AssignLiteral("<!");
theStr.Append(aToken->GetStringValue());
// Treat CDATA sections specially because they remember their last
// character and can come back malformed.
// theStr.AppendLiteral(">");
result=WriteTag(mCDATATag,theStr,0,PR_TRUE);
if (!aToken->IsInError()) {
theStr.AppendLiteral(">");
}
result=WriteTag(mCDATATag,theStr,0,aToken->IsInError());
}
break;
@ -1133,8 +1133,10 @@ NS_IMETHODIMP CViewSourceHTML::HandleToken(CToken* aToken,nsIParser* aParser) {
nsAutoString theStr;
theStr.AssignLiteral("<!");
theStr.Append(aToken->GetStringValue());
theStr.AppendLiteral(">");
result=WriteTag(mMarkupDeclaration,theStr,0,PR_TRUE);
if (!aToken->IsInError()) {
theStr.AppendLiteral(">");
}
result=WriteTag(mMarkupDeclaration,theStr,0,aToken->IsInError());
}
break;
@ -1142,14 +1144,14 @@ NS_IMETHODIMP CViewSourceHTML::HandleToken(CToken* aToken,nsIParser* aParser) {
{
nsAutoString theStr;
aToken->AppendSourceTo(theStr);
result=WriteTag(mCommentTag,theStr,0,PR_TRUE);
result=WriteTag(mCommentTag,theStr,0,aToken->IsInError());
}
break;
case eToken_doctypeDecl:
{
const nsAString& doctypeValue = aToken->GetStringValue();
result=WriteTag(mDocTypeTag,doctypeValue,0,PR_TRUE);
result=WriteTag(mDocTypeTag,doctypeValue,0,aToken->IsInError());
}
break;
@ -1182,7 +1184,7 @@ NS_IMETHODIMP CViewSourceHTML::HandleToken(CToken* aToken,nsIParser* aParser) {
case eToken_text:
{
const nsAString& str = aToken->GetStringValue();
result=WriteTag(mText,str,aToken->GetAttributeCount(),PR_TRUE);
result=WriteTag(mText,str,aToken->GetAttributeCount(),aToken->IsInError());
++mTokenCount;
if (NS_VIEWSOURCE_TOKENS_PER_BLOCK > 0 &&
mTokenCount > NS_VIEWSOURCE_TOKENS_PER_BLOCK && !str.IsEmpty()) {
@ -1204,12 +1206,12 @@ NS_IMETHODIMP CViewSourceHTML::HandleToken(CToken* aToken,nsIParser* aParser) {
theStr.Assign(NS_LITERAL_STRING("#") + theStr);
}
}
result=WriteTag(mEntityTag,theStr,0,PR_FALSE);
result=WriteTag(mEntityTag,theStr,0,aToken->IsInError());
}
break;
case eToken_instruction:
result=WriteTag(mPITag,aToken->GetStringValue(),0,PR_TRUE);
result=WriteTag(mPITag,aToken->GetStringValue(),0,aToken->IsInError());
default:
result=NS_OK;

Просмотреть файл

@ -85,7 +85,7 @@ private:
nsresult WriteTag(PRInt32 tagType,
const nsAString &aText,
PRInt32 attrCount,
PRBool aNewlineRequired);
PRBool aTagInError);
nsresult WriteAttributes(PRInt32 attrCount);
nsresult GenerateSummary();