mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 14:22:01 +00:00
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.
This commit is contained in:
parent
39cf91dcf0
commit
fb406fbfdd
@ -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)))
|
||||
|
@ -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)
|
||||
|
@ -54,6 +54,9 @@ TEST_FILES = \
|
||||
htmltable.out \
|
||||
xifstuff.xif \
|
||||
xifstuff.out \
|
||||
doctype.xif \
|
||||
xifdtplain.out \
|
||||
xifdthtml.out \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
@ -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
|
||||
|
@ -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%
|
||||
|
17
htmlparser/tests/outsinks/doctype.xif
Normal file
17
htmlparser/tests/outsinks/doctype.xif
Normal file
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0"?>
|
||||
<!DOCTYPE xif>
|
||||
<encode selection="1"/>
|
||||
<section>
|
||||
<section_head>
|
||||
<document_info charset="ISO-8859-1"/>
|
||||
</section_head>
|
||||
<section_body>
|
||||
<markup_declaration>
|
||||
<content>DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"</content>
|
||||
</markup_declaration>
|
||||
<container isa="body">
|
||||
<content>Here is some content inside a doctype
|
||||
</content>
|
||||
</container><!--body-->
|
||||
</section_body>
|
||||
</section>
|
@ -46,6 +46,9 @@ TEST_FILES = \
|
||||
xifstuff.out \
|
||||
htmltable.html \
|
||||
htmltable.out \
|
||||
doctype.xif \
|
||||
xifdtplain.out \
|
||||
xifdthtml.out \
|
||||
$(NULL)
|
||||
|
||||
LINCS= \
|
||||
|
3
htmlparser/tests/outsinks/xifdthtml.out
Normal file
3
htmlparser/tests/outsinks/xifdthtml.out
Normal file
@ -0,0 +1,3 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
|
||||
<body>Here is some content inside a doctype
|
||||
</body>
|
1
htmlparser/tests/outsinks/xifdtplain.out
Normal file
1
htmlparser/tests/outsinks/xifdtplain.out
Normal file
@ -0,0 +1 @@
|
||||
Here is some content inside a doctype
|
@ -1,4 +1,3 @@
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<!--
|
||||
|
@ -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)))
|
||||
|
@ -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)
|
||||
|
@ -54,6 +54,9 @@ TEST_FILES = \
|
||||
htmltable.out \
|
||||
xifstuff.xif \
|
||||
xifstuff.out \
|
||||
doctype.xif \
|
||||
xifdtplain.out \
|
||||
xifdthtml.out \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
@ -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
|
||||
|
@ -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%
|
||||
|
17
parser/htmlparser/tests/outsinks/doctype.xif
Normal file
17
parser/htmlparser/tests/outsinks/doctype.xif
Normal file
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0"?>
|
||||
<!DOCTYPE xif>
|
||||
<encode selection="1"/>
|
||||
<section>
|
||||
<section_head>
|
||||
<document_info charset="ISO-8859-1"/>
|
||||
</section_head>
|
||||
<section_body>
|
||||
<markup_declaration>
|
||||
<content>DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"</content>
|
||||
</markup_declaration>
|
||||
<container isa="body">
|
||||
<content>Here is some content inside a doctype
|
||||
</content>
|
||||
</container><!--body-->
|
||||
</section_body>
|
||||
</section>
|
@ -46,6 +46,9 @@ TEST_FILES = \
|
||||
xifstuff.out \
|
||||
htmltable.html \
|
||||
htmltable.out \
|
||||
doctype.xif \
|
||||
xifdtplain.out \
|
||||
xifdthtml.out \
|
||||
$(NULL)
|
||||
|
||||
LINCS= \
|
||||
|
3
parser/htmlparser/tests/outsinks/xifdthtml.out
Normal file
3
parser/htmlparser/tests/outsinks/xifdthtml.out
Normal file
@ -0,0 +1,3 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
|
||||
<body>Here is some content inside a doctype
|
||||
</body>
|
1
parser/htmlparser/tests/outsinks/xifdtplain.out
Normal file
1
parser/htmlparser/tests/outsinks/xifdtplain.out
Normal file
@ -0,0 +1 @@
|
||||
Here is some content inside a doctype
|
@ -1,4 +1,3 @@
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<!--
|
||||
|
Loading…
Reference in New Issue
Block a user