From 3843cdc3aab46dc9528c545527b5985b41a673c9 Mon Sep 17 00:00:00 2001 From: Geoff McLane Date: Sat, 17 Mar 2018 14:24:27 +0100 Subject: [PATCH 1/3] Is #692 - correct message titles in head --- src/message.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/message.c b/src/message.c index eb097de..0c1ff4c 100644 --- a/src/message.c +++ b/src/message.c @@ -851,8 +851,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; From 8d5ff2c5141ae10b85c26277f4d3ef56d37b26da Mon Sep 17 00:00:00 2001 From: Geoff McLane Date: Tue, 27 Mar 2018 15:36:15 +0200 Subject: [PATCH 2/3] Is #692 - Add a 'CleanHead' service --- src/clean.c | 31 +++++++++++++++++++++++++++++++ src/clean.h | 3 +++ src/tidylib.c | 2 ++ 3 files changed, 36 insertions(+) diff --git a/src/clean.c b/src/clean.c index e96dd3f..61c9596 100644 --- a/src/clean.c +++ b/src/clean.c @@ -2780,6 +2780,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/tidylib.c b/src/tidylib.c index 67d7a37..7396c74 100644 --- a/src/tidylib.c +++ b/src/tidylib.c @@ -2153,6 +2153,8 @@ int tidyDocCleanAndRepair( TidyDocImpl* doc ) } } + TY_(CleanHead)(doc); /* Is #692 - discard multiple tags */ + #if defined(ENABLE_DEBUG_LOG) SPRTF("All nodes AFTER clean and repair\n"); dbg_show_all_nodes( doc, &doc->root, 0 ); From 65aa1bdd8c12eeca384681f609a9000c13e2c161 Mon Sep 17 00:00:00 2001 From: Jim Derry <balthisar@gmail.com> Date: Wed, 30 Jun 2021 09:25:37 -0400 Subject: [PATCH 3/3] Added test cases to this PR. --- .../cases/github-cases/case-692@1.html | 17 +++++++++++++++++ .../cases/github-expects/case-692.html | 18 ++++++++++++++++++ .../cases/github-expects/case-692.txt | 17 +++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100755 regression_testing/cases/github-cases/case-692@1.html create mode 100644 regression_testing/cases/github-expects/case-692.html create mode 100644 regression_testing/cases/github-expects/case-692.txt 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 @@ +<!-- +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 + 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