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

All tags within <head> are pushed inside of <title> #144

Closed
xCJPECKOVERx opened this issue Nov 24, 2016 · 6 comments
Closed

All tags within <head> are pushed inside of <title> #144

xCJPECKOVERx opened this issue Nov 24, 2016 · 6 comments
Labels

Comments

@xCJPECKOVERx
Copy link

When using layout:decorate all tags within get put inside of the <title> tag as plain text. This includes scripts and links.
Results in a <title> such as:

<title> Exception Logs<script> $( document ).ready(function() { $('#errorSelect').on("change", function() { $(this).parents('form').submit(); }); }); </script> </title>
@ultraq
Copy link
Owner

ultraq commented Nov 25, 2016

Heya @xCJPECKOVERx, that's a really weird bug! To help me figure it out, would you be able to give a sample template & layout that can produce that kind of output? Also, what versions of the layout dialect and Thymeleaf are you using?

@xCJPECKOVERx
Copy link
Author

Thymeleaf version: 3.0.2.RELEASE
LayoutDialect version: 2.1.1
I've managed to narrow down the bug to only happening when nesting layouts.
In my project I have a master (importing links and scripts), a header (decorated by master), and finally the content pages (decorated by the header).

Note: I'm also using Spring and have templateResolver, templateEngine, and viewResolver setup per Thymeleaf documentation and have added the LayoutDialect to the templateEngine.

master.html:

<html>
    <head>
        <title>default title</title>
    </head>
    <body>
        <div layout:fragment="page"></div>
    </body>
</html>

header.html:

<html layout:decorate="~{layouts/master}">
    <head></head>
    <body>
        <div layout:fragment="page">
            <a th:href="@{/home}">Home</a>
            <div layout:fragment="content"></div>
       </div>
    </body>
</html>

home.html:

<html layout:decorate="~{layouts/header}">
    <head>
        <title>Some Title</title>
        <script>alert('hello');</script>
    </head>
    <body>
        <div layout:fragment="content">
            <p>Some Content</p>
       </div>
    </body>
</html>

ultraq added a commit that referenced this issue Nov 28, 2016
@ultraq ultraq added the bug label Nov 28, 2016
@ultraq
Copy link
Owner

ultraq commented Nov 28, 2016

Cool cool, managed to replicate it in the linked test/commit.

@ultraq
Copy link
Owner

ultraq commented Nov 29, 2016

I've had a look at it and found there was something wrong with the code I had that tried to insert what Thymeleaf 3 calls "models" (eg: an opening element, everything inside it, and the matching closing element) inside elements that are closed immediately, like your <head></head> tags. The code in question assumes that there's some whitespace around to duplicate (this is to create a cleaner-looking output) but without any it just inserts that <script> model into the wrong place.

The problem also appeared in the first decoration, so wasn't a multiple layouts issue.

I've uploaded a 2.1.2-SNAPSHOT version to Maven which has a fix for this. Could you give it a try in your project to see if it works for you?

@xCJPECKOVERx
Copy link
Author

I've tried the fix and it does work. Good stuff!

@ultraq ultraq closed this as completed in 3f9350c Nov 30, 2016
ultraq added a commit that referenced this issue Nov 30, 2016
ultraq added a commit that referenced this issue Nov 30, 2016
@ultraq
Copy link
Owner

ultraq commented Nov 30, 2016

Awesome! I've got no other bugs to fix for now, so I'll get this into a release very soon.

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

No branches or pull requests

2 participants