From fb406fbfdd850c2d1120045a212d0550d4a00c03 Mon Sep 17 00:00:00 2001 From: "akkana%netscape.com" Date: Wed, 23 Feb 2000 01:23:29 +0000 Subject: [PATCH] 19428: fix copying from a document with a doctype. Also add test cases to notice this if it ever regresses. Fix from harishd, r=me, a=rickg. --- htmlparser/src/nsHTMLToTXTSinkStream.cpp | 2 +- htmlparser/src/nsXIFDTD.cpp | 32 +++---------------- htmlparser/tests/outsinks/Makefile.in | 3 ++ htmlparser/tests/outsinks/TestOutSinks | 16 +++++++++- htmlparser/tests/outsinks/TestOutSinks.bat | 14 +++++++- htmlparser/tests/outsinks/doctype.xif | 17 ++++++++++ htmlparser/tests/outsinks/makefile.win | 3 ++ htmlparser/tests/outsinks/xifdthtml.out | 3 ++ htmlparser/tests/outsinks/xifdtplain.out | 1 + htmlparser/tests/outsinks/xifstuff.out | 1 - .../htmlparser/src/nsHTMLToTXTSinkStream.cpp | 2 +- parser/htmlparser/src/nsXIFDTD.cpp | 32 +++---------------- parser/htmlparser/tests/outsinks/Makefile.in | 3 ++ parser/htmlparser/tests/outsinks/TestOutSinks | 16 +++++++++- .../tests/outsinks/TestOutSinks.bat | 14 +++++++- parser/htmlparser/tests/outsinks/doctype.xif | 17 ++++++++++ parser/htmlparser/tests/outsinks/makefile.win | 3 ++ .../htmlparser/tests/outsinks/xifdthtml.out | 3 ++ .../htmlparser/tests/outsinks/xifdtplain.out | 1 + parser/htmlparser/tests/outsinks/xifstuff.out | 1 - 20 files changed, 122 insertions(+), 62 deletions(-) create mode 100644 htmlparser/tests/outsinks/doctype.xif create mode 100644 htmlparser/tests/outsinks/xifdthtml.out create mode 100644 htmlparser/tests/outsinks/xifdtplain.out create mode 100644 parser/htmlparser/tests/outsinks/doctype.xif create mode 100644 parser/htmlparser/tests/outsinks/xifdthtml.out create mode 100644 parser/htmlparser/tests/outsinks/xifdtplain.out diff --git a/htmlparser/src/nsHTMLToTXTSinkStream.cpp b/htmlparser/src/nsHTMLToTXTSinkStream.cpp index 3f1aae8e93e3..ac872bc83930 100644 --- a/htmlparser/src/nsHTMLToTXTSinkStream.cpp +++ b/htmlparser/src/nsHTMLToTXTSinkStream.cpp @@ -426,7 +426,7 @@ nsHTMLToTXTSinkStream::OpenContainer(const nsIParserNode& aNode) printf("OpenContainer: %d ", type); #endif const nsString& name = aNode.GetText(); - if (name.Equals("XIF_DOC_INFO")) + if (name.Equals("document_info")) { nsString value; if (NS_SUCCEEDED(GetValueOfAttribute(aNode, "charset", value))) diff --git a/htmlparser/src/nsXIFDTD.cpp b/htmlparser/src/nsXIFDTD.cpp index 79dbd298a8ee..c69dd936853e 100644 --- a/htmlparser/src/nsXIFDTD.cpp +++ b/htmlparser/src/nsXIFDTD.cpp @@ -603,11 +603,6 @@ nsresult nsXIFDTD::HandleStartToken(CToken* aToken) { ProcessEncodeTag(node); break; - case eXIFTag_document_info: - ProcessDocumentInfoTag(node); - break; - - case eXIFTag_attr: AddAttribute(node); break; @@ -633,6 +628,11 @@ nsresult nsXIFDTD::HandleStartToken(CToken* aToken) { AddCSSDeclaration(node); break; + case eXIFTag_document_info: + // This is XIF only tag. For HTML it's userdefined. + node.mToken->SetTypeID(eHTMLTag_userdefined); + // fall through to call OpenContainer: + case eXIFTag_markupDecl: mSink->OpenContainer(node); break; @@ -1436,28 +1436,6 @@ void nsXIFDTD::ProcessEntityTag(const nsIParserNode& aNode) } } - -void nsXIFDTD::ProcessDocumentInfoTag(const nsIParserNode& aNode) -{ - nsString value; - nsString key("charset"); - - if (GetAttribute(aNode,key,value)) - { - nsString tmpString("document_info"); - PushNodeAndToken(tmpString); - nsIParserNode* top = PeekNode(); - if (top != nsnull) - { - CAttributeToken* attribute = new CAttributeToken(key,value); - ((nsCParserNode*)top)->AddAttribute(attribute); - } - } -} - - - - /*** CSS Methods ****/ void nsXIFDTD::BeginCSSStyleSheet(const nsIParserNode& aNode) diff --git a/htmlparser/tests/outsinks/Makefile.in b/htmlparser/tests/outsinks/Makefile.in index 86d5f0e6114c..8885d4da8303 100644 --- a/htmlparser/tests/outsinks/Makefile.in +++ b/htmlparser/tests/outsinks/Makefile.in @@ -54,6 +54,9 @@ TEST_FILES = \ htmltable.out \ xifstuff.xif \ xifstuff.out \ + doctype.xif \ + xifdtplain.out \ + xifdthtml.out \ $(NULL) include $(topsrcdir)/config/rules.mk diff --git a/htmlparser/tests/outsinks/TestOutSinks b/htmlparser/tests/outsinks/TestOutSinks index 4e38b770982b..93ed9db442cd 100755 --- a/htmlparser/tests/outsinks/TestOutSinks +++ b/htmlparser/tests/outsinks/TestOutSinks @@ -44,7 +44,7 @@ endif echo "Testing simple html to plaintext formatting ..." TestOutput -i text/html -o text/plain -f 34 -w 70 -c OutTestData/simplefmt.out OutTestData/simple.html if ($status != 0) then - echo "Simple copy test failed.\n" + echo "Simple formatting test failed.\n" set errmsg = ($errmsg "simplefmt.out") endif @@ -90,6 +90,20 @@ if ($status != 0) then set errmsg = ($errmsg "htmltable.out") endif +echo "Testing XIF to plain with doctype (bug 28447) ..." +TestOutput -i text/xif -o text/plain -f 2 -c OutTestData/xifdtplain.out OutTestData/doctype.xif +if ($status != 0) then + echo "XIF to plain with doctype failed." + set errmsg = ($errmsg "xifdtplain.out") +endif + +echo "Testing XIF to html with doctype ..." +TestOutput -i text/xif -o text/html -f 0 -c OutTestData/xifdthtml.out OutTestData/doctype.xif +if ($status != 0) then + echo "XIF to html with doctype failed." + set errmsg = ($errmsg "xifdthtml.out") +endif + if ("$errmsg" != "") then echo " " echo TESTS FAILED: $errmsg diff --git a/htmlparser/tests/outsinks/TestOutSinks.bat b/htmlparser/tests/outsinks/TestOutSinks.bat index 9363ad99513f..d22a2789b307 100644 --- a/htmlparser/tests/outsinks/TestOutSinks.bat +++ b/htmlparser/tests/outsinks/TestOutSinks.bat @@ -28,13 +28,17 @@ set errmsg= set has_err= echo Testing simple html to html ... -TestOutput -i text/html -o text\html -f 0 -c OutTestData/simple.html OutTestData/simple.html +TestOutput -i text/html -o text/html -f 0 -c OutTestData/simple.html OutTestData/simple.html if errorlevel 1 echo Simple html to html failed (%errorlevel%). && set has_err=1 && set errmsg=%errmsg% simple.html echo Testing simple copy case ... TestOutput -i text/html -o text/plain -f 0 -w 0 -c OutTestData/simplecopy.out OutTestData/simple.html if errorlevel 1 echo Simple copy test failed. && set has_err=1 && set errmsg=%errmsg% simplecopy.out +echo "Testing simple html to plaintext formatting ..." +TestOutput -i text/html -o text/plain -f 34 -w 70 -c OutTestData/simplefmt.out OutTestData/simple.html +if errorlevel 1 echo Simple formatting test failed. && set has_err=1 && set errmsg=%errmsg% plainnowrap.out + echo Testing non-wrapped plaintext ... TestOutput -i text/html -o text/plain -f 0 -w 0 -c OutTestData/plainnowrap.out OutTestData/plain.html if errorlevel 1 echo Non-wrapped plaintext test failed. && set has_err=1 && set errmsg=%errmsg% plainnowrap.out @@ -59,6 +63,14 @@ echo Testing HTML Table to Text ... TestOutput -i text/html -o text/plain -c OutTestData/htmltable.out OutTestData/htmltable.html if errorlevel 1 echo HTML Table to Plain text failed (%errorlevel%). && set has_err=1 && set errmsg=%errmsg% htmltable.out +echo "Testing XIF to plain with doctype (bug 28447) ..." +TestOutput -i text/xif -o text/plain -f 2 -c OutTestData/xifdtplain.out OutTestData/doctype.xif +if errorlevel 1 echo XIF to plain with doctype failed (%errorlevel%). && set has_err=1 && set errmsg=%errmsg% xifdtplain.out + +REM echo "Testing XIF to html with doctype ..." +REM TestOutput -i text/xif -o text/html -f 0 -c OutTestData/xifdthtml.out OutTestData/doctype.xif +REM if errorlevel 1 echo XIF to html with doctype failed (%errorlevel%). && set has_err=1 && set errmsg=%errmsg% xifdthtml.out + if %has_err% == 0 goto success echo. echo TESTS FAILED: %errmsg% diff --git a/htmlparser/tests/outsinks/doctype.xif b/htmlparser/tests/outsinks/doctype.xif new file mode 100644 index 000000000000..0a691a75e034 --- /dev/null +++ b/htmlparser/tests/outsinks/doctype.xif @@ -0,0 +1,17 @@ + + + +
+ + + + + +DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN" + + +Here is some content inside a doctype + + + +
diff --git a/htmlparser/tests/outsinks/makefile.win b/htmlparser/tests/outsinks/makefile.win index 80885f31ce37..b0ad74fa95e7 100644 --- a/htmlparser/tests/outsinks/makefile.win +++ b/htmlparser/tests/outsinks/makefile.win @@ -46,6 +46,9 @@ TEST_FILES = \ xifstuff.out \ htmltable.html \ htmltable.out \ + doctype.xif \ + xifdtplain.out \ + xifdthtml.out \ $(NULL) LINCS= \ diff --git a/htmlparser/tests/outsinks/xifdthtml.out b/htmlparser/tests/outsinks/xifdthtml.out new file mode 100644 index 000000000000..31fa952fb891 --- /dev/null +++ b/htmlparser/tests/outsinks/xifdthtml.out @@ -0,0 +1,3 @@ + +Here is some content inside a doctype + diff --git a/htmlparser/tests/outsinks/xifdtplain.out b/htmlparser/tests/outsinks/xifdtplain.out new file mode 100644 index 000000000000..8b2ae30d607d --- /dev/null +++ b/htmlparser/tests/outsinks/xifdtplain.out @@ -0,0 +1 @@ +Here is some content inside a doctype diff --git a/htmlparser/tests/outsinks/xifstuff.out b/htmlparser/tests/outsinks/xifstuff.out index f611e9533331..0b52b27b3345 100644 --- a/htmlparser/tests/outsinks/xifstuff.out +++ b/htmlparser/tests/outsinks/xifstuff.out @@ -1,4 +1,3 @@ - + + diff --git a/parser/htmlparser/tests/outsinks/makefile.win b/parser/htmlparser/tests/outsinks/makefile.win index 80885f31ce37..b0ad74fa95e7 100644 --- a/parser/htmlparser/tests/outsinks/makefile.win +++ b/parser/htmlparser/tests/outsinks/makefile.win @@ -46,6 +46,9 @@ TEST_FILES = \ xifstuff.out \ htmltable.html \ htmltable.out \ + doctype.xif \ + xifdtplain.out \ + xifdthtml.out \ $(NULL) LINCS= \ diff --git a/parser/htmlparser/tests/outsinks/xifdthtml.out b/parser/htmlparser/tests/outsinks/xifdthtml.out new file mode 100644 index 000000000000..31fa952fb891 --- /dev/null +++ b/parser/htmlparser/tests/outsinks/xifdthtml.out @@ -0,0 +1,3 @@ + +Here is some content inside a doctype + diff --git a/parser/htmlparser/tests/outsinks/xifdtplain.out b/parser/htmlparser/tests/outsinks/xifdtplain.out new file mode 100644 index 000000000000..8b2ae30d607d --- /dev/null +++ b/parser/htmlparser/tests/outsinks/xifdtplain.out @@ -0,0 +1 @@ +Here is some content inside a doctype diff --git a/parser/htmlparser/tests/outsinks/xifstuff.out b/parser/htmlparser/tests/outsinks/xifstuff.out index f611e9533331..0b52b27b3345 100644 --- a/parser/htmlparser/tests/outsinks/xifstuff.out +++ b/parser/htmlparser/tests/outsinks/xifstuff.out @@ -1,4 +1,3 @@ -