Merge pull request #927 from htacg/issue-692
Issue #692 - too many titles
This commit is contained in:
commit
e77d16ae75
17
regression_testing/cases/github-cases/case-692@1.html
Executable file
17
regression_testing/cases/github-cases/case-692@1.html
Executable file
|
@ -0,0 +1,17 @@
|
|||
<!--
|
||||
This test case represents HTML Tidy issue #692, which describes
|
||||
how Tidy misbehaves when there are multiple <title> elements present.
|
||||
The reason this change is needed is to alert the user that multiple
|
||||
<title> elements are present, and to deleted all but the first title
|
||||
element, which is consistent with the behavior of mainline web browers
|
||||
as of this commit date.
|
||||
-->
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<HEAD>
|
||||
<TITLE>Test stuff</TITLE>
|
||||
<TITLE>As if one title isn't enough</TITLE>
|
||||
</HEAD>
|
||||
<BODY>
|
||||
<P>This is my paragraph</P>
|
||||
</BODY>
|
||||
</HTML>
|
18
regression_testing/cases/github-expects/case-692.html
Normal file
18
regression_testing/cases/github-expects/case-692.html
Normal file
|
@ -0,0 +1,18 @@
|
|||
<!--
|
||||
This test case represents HTML Tidy issue #692, which describes
|
||||
how Tidy misbehaves when there are multiple <title> elements present.
|
||||
The reason this change is needed is to alert the user that multiple
|
||||
<title> elements are present, and to deleted all but the first title
|
||||
element, which is consistent with the behavior of mainline web browers
|
||||
as of this commit date.
|
||||
-->
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<title>Test stuff</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>This is my paragraph</p>
|
||||
</body>
|
||||
</html>
|
17
regression_testing/cases/github-expects/case-692.txt
Normal file
17
regression_testing/cases/github-expects/case-692.txt
Normal file
|
@ -0,0 +1,17 @@
|
|||
line 10 column 5 - Warning: too many title elements in <head>
|
||||
line 10 column 5 - Info: <head> previously mentioned
|
||||
line 12 column 9 - Warning: discarding unexpected <title>
|
||||
Info: Doctype given is "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
Info: Document content looks like XHTML 1.0 Strict
|
||||
Tidy found 2 warnings and 0 errors!
|
||||
|
||||
About HTML Tidy: https://github.com/htacg/tidy-html5
|
||||
Bug reports and comments: https://github.com/htacg/tidy-html5/issues
|
||||
Official mailing list: https://lists.w3.org/Archives/Public/public-htacg/
|
||||
Latest HTML specification: http://dev.w3.org/html5/spec-author-view/
|
||||
Validate your HTML documents: http://validator.w3.org/nu/
|
||||
Lobby your company to join the W3C: http://www.w3.org/Consortium
|
||||
|
||||
Do you speak a language other than English, or a different variant of
|
||||
English? Consider helping us to localize HTML Tidy. For details please see
|
||||
https://github.com/htacg/tidy-html5/blob/master/README/LOCALIZE.md
|
31
src/clean.c
31
src/clean.c
|
@ -2782,6 +2782,37 @@ void TY_(CleanStyle)(TidyDocImpl* doc, Node *html)
|
|||
/* ==================================================
|
||||
*/
|
||||
|
||||
/*
|
||||
* CleanHead - clean the head node, if it exists, and we
|
||||
* are going to show it in the output.
|
||||
* Issue #692 - Remove multiple title elements
|
||||
*/
|
||||
void TY_(CleanHead)(TidyDocImpl* doc)
|
||||
{
|
||||
Node *head, *node, *next;
|
||||
uint titles = 0;
|
||||
if (cfgAutoBool(doc, TidyBodyOnly) == TidyYesState)
|
||||
return; /* not going to show head, so forget it */
|
||||
head = TY_(FindHEAD)(doc);
|
||||
if (!head)
|
||||
return;
|
||||
node = head->content;
|
||||
while (node)
|
||||
{
|
||||
next = node->next; /* get any 'next' */
|
||||
if (nodeIsTITLE(node))
|
||||
{
|
||||
titles++;
|
||||
if (titles > 1)
|
||||
{
|
||||
TY_(Report)(doc, head, node, DISCARDING_UNEXPECTED);
|
||||
TY_(DiscardElement)(doc, node); /* delete this node */
|
||||
}
|
||||
}
|
||||
node = next;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* local variables:
|
||||
* mode: c
|
||||
|
|
|
@ -75,5 +75,8 @@ void TY_(FixLanguageInformation)(TidyDocImpl* doc, Node* node, Bool wantXmlLang,
|
|||
|
||||
/* Issue #567 - move style elements from body to head */
|
||||
void TY_(CleanStyle)(TidyDocImpl* doc, Node *html);
|
||||
/* Issue #692 - discard multiple titles */
|
||||
void TY_(CleanHead)(TidyDocImpl* doc);
|
||||
|
||||
|
||||
#endif /* __CLEAN_H__ */
|
||||
|
|
|
@ -853,8 +853,10 @@ TidyMessageImpl *formatStandard(TidyDocImpl* doc, Node *element, Node *node, uin
|
|||
|
||||
case COERCE_TO_ENDTAG:
|
||||
case NON_MATCHING_ENDTAG:
|
||||
case TOO_MANY_ELEMENTS_IN:
|
||||
return TY_(tidyMessageCreateWithNode)(doc, rpt, code, level, node->element, node->element );
|
||||
case TOO_MANY_ELEMENTS_IN:
|
||||
return TY_(tidyMessageCreateWithNode)(doc, rpt, code, level, node->element, element->element);
|
||||
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
|
|
@ -2169,6 +2169,8 @@ int tidyDocCleanAndRepair( TidyDocImpl* doc )
|
|||
}
|
||||
}
|
||||
|
||||
TY_(CleanHead)(doc); /* Is #692 - discard multiple <title> tags */
|
||||
|
||||
#if defined(ENABLE_DEBUG_LOG)
|
||||
SPRTF("All nodes AFTER clean and repair\n");
|
||||
dbg_show_all_nodes( doc, &doc->root, 0 );
|
||||
|
|
Loading…
Reference in a new issue