Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

template tag should be allowed in head #836

Closed
salortiz opened this issue Jul 30, 2019 · 2 comments
Closed

template tag should be allowed in head #836

salortiz opened this issue Jul 30, 2019 · 2 comments

Comments

@salortiz
Copy link

Per the spec the template element can be used in head

The current released v5.6.0 produces "inserting implicit <body>" followed by "discarding unexpected </head>" among other warnings and the template is moved to body

Can be tested with:

<!DOCTYPE html><html><head>
<template>hi</template>
</head><body></body>
@geoffmcl
Copy link
Contributor

geoffmcl commented Aug 3, 2019

@salortiz thank you for the issue...

Have not had time to fully read the specs, need some help, support, ... in that...

But if it is allowed in the head, then I think the fix is easy -

diff --git a/src/tags.c b/src/tags.c
index af2b7d9..f2a1907 100644
--- a/src/tags.c
+++ b/src/tags.c
@@ -324,7 +324,7 @@ static Dict tag_defs[] =
   { TidyTag_SECTION,     "section",      VERS_ELEM_SECTION,     &TY_(W3CAttrsFor_SECTION)[0],     (CM_BLOCK),                    TY_(ParseBlock),     NULL           },
   { TidyTag_SOURCE,      "source",       VERS_ELEM_SOURCE,      &TY_(W3CAttrsFor_SOURCE)[0],      (CM_BLOCK|CM_INLINE|CM_EMPTY), TY_(ParseBlock),     NULL           },
   { TidyTag_SUMMARY,     "summary",      VERS_ELEM_SUMMARY,     &TY_(W3CAttrsFor_SUMMARY)[0],     (CM_BLOCK),                    TY_(ParseInline),    NULL           },
-  { TidyTag_TEMPLATE,    "template",     VERS_ELEM_TEMPLATE,    &TY_(W3CAttrsFor_TEMPLATE)[0],    (CM_BLOCK),                    TY_(ParseBlock),     NULL           },
+  { TidyTag_TEMPLATE,    "template",     VERS_ELEM_TEMPLATE,    &TY_(W3CAttrsFor_TEMPLATE)[0],    (CM_BLOCK|CM_HEAD),            TY_(ParseBlock),     NULL           },
   { TidyTag_TIME,        "time",         VERS_ELEM_TIME,        &TY_(W3CAttrsFor_TIME)[0],        (CM_INLINE),                   TY_(ParseInline),    NULL           },
   { TidyTag_TRACK,       "track",        VERS_ELEM_TRACK,       &TY_(W3CAttrsFor_TRACK)[0],       (CM_BLOCK|CM_EMPTY),           TY_(ParseBlock),     NULL           },
   { TidyTag_VIDEO,       "video",        VERS_ELEM_VIDEO,       &TY_(W3CAttrsFor_VIDEO)[0],       (CM_BLOCK|CM_INLINE),          TY_(ParseBlock),     NULL           },

That is, add the CM_HEAD bit into the template tag_defs entry... if it is confirmed it is allowed...

In ParseHead the following code checks if the node, in this case template, contains the CM_HEAD bit, and the code comments say it all, if the tag->model fails -

       /*
         if it doesn't belong in the head then
         treat as implicit end of head and deal
         with as part of the body
        */
        if (!(node->tag->model & CM_HEAD))
        {
            /* #545067 Implicit closing of head broken - warn only for XHTML input */
            if ( lexer->isvoyager )
                TY_(Report)(doc, head, node, TAG_NOT_ALLOWED_IN );
            TY_(UngetToken)( doc );
            break;
        }

Will now proceed to try to test this... and check for any other unwanted consequences of this change...

To facilitate testing have added your sample, as in_836.html, to my test repo, and a 2nd in_836-1.html, which passes W3C validation...

Appreciate if you or others could test this patch, and report, comment, etc... thanks...

@salortiz
Copy link
Author

salortiz commented Aug 5, 2019

@geoffmcl,

Thank you for your response, I can confirm that your patch fixes my issue.

About the spec, you can review also "metadata content", one of the categories of Template, and The head Element.

Regards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants