diff --git a/regression_testing/cases/github-cases/case-692@1.html b/regression_testing/cases/github-cases/case-692@1.html new file mode 100755 index 0000000..0cefac1 --- /dev/null +++ b/regression_testing/cases/github-cases/case-692@1.html @@ -0,0 +1,17 @@ + + + + Test stuff + As if one title isn't enough + + +

This is my paragraph

+ + diff --git a/regression_testing/cases/github-expects/case-692.html b/regression_testing/cases/github-expects/case-692.html new file mode 100644 index 0000000..f942f2e --- /dev/null +++ b/regression_testing/cases/github-expects/case-692.html @@ -0,0 +1,18 @@ + + + + + Test stuff + + +

This is my paragraph

+ + diff --git a/regression_testing/cases/github-expects/case-692.txt b/regression_testing/cases/github-expects/case-692.txt new file mode 100644 index 0000000..31cc015 --- /dev/null +++ b/regression_testing/cases/github-expects/case-692.txt @@ -0,0 +1,17 @@ +line 10 column 5 - Warning: too many title elements in +line 10 column 5 - Info: previously mentioned +line 12 column 9 - Warning: discarding unexpected +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 diff --git a/src/clean.c b/src/clean.c index 6602ff9..a4aa815 100644 --- a/src/clean.c +++ b/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 diff --git a/src/clean.h b/src/clean.h index f0ef7a6..c765e81 100644 --- a/src/clean.h +++ b/src/clean.h @@ -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__ */ diff --git a/src/message.c b/src/message.c index ee2e6c6..9f89f3e 100644 --- a/src/message.c +++ b/src/message.c @@ -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; diff --git a/src/tidylib.c b/src/tidylib.c index 4d57510..86fd31c 100644 --- a/src/tidylib.c +++ b/src/tidylib.c @@ -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 );