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

Incorrect HTML generated when default codec is html #3

Open
jeremydawson opened this issue May 14, 2012 · 2 comments
Open

Incorrect HTML generated when default codec is html #3

jeremydawson opened this issue May 14, 2012 · 2 comments
Assignees
Labels

Comments

@jeremydawson
Copy link

Thank you for the nice plugin with good documentation.

In the Config.groovy for my app, I have the default codec set to html:

grails.views.default.codec = "html"

This causes all content inside ${ } to be HTML-escaped. It looks like there are a few spots in the plugin's templates that assume that this parameter is set to "none", as the plugin generates the following HTML:

<form id="fileupload" action="/myController/upload" method="POST" enctype=&quot;multipart/form-data&quot;>

and

&lt;!-- The table listing the files available for upload/download --&gt;
&lt;table class=&quot;table table-striped&quot;&gt;
  &lt;tbody class=&amp;quot;files&amp;quot; data-toggle=&quot;modal-gallery&quot; data-target=&quot;#modal-gallery&quot;&gt;

  &lt;/tbody&gt;
&lt;/table&gt;

If I switch the codec to "none" then the HTML gets generated properly, but there are other places in my app that assume this is set to "html".

My proposed solution is to modify the plugin templates to use the <%= %> syntax instead of ${ } when HTML is being produced. So in _list.gsp the following line:

  <tbody ${filesContainer ? (filesContainer.startsWith('.') ? 'class="' + filesContainer.substring(1) + '"' : 'id="' + filesContainer.substring(1) + '"') : 'class="files"'} data-toggle="modal-gallery" data-target="#modal-gallery">

would be replaced with:

<tbody <%=filesContainer ? (filesContainer.startsWith('.') ? 'class="' + filesContainer.substring(1) + '"' : 'id="' + filesContainer.substring(1) + '"') : 'class="files"' %> data-toggle="modal-gallery" data-target="#modal-gallery">

In _form.gsp, replace:

<form id="${id}" action="${url}" method="${type}" ${multipart ? 'enctype="multipart/form-data"' : ''}>

with:

<form id="${id}" action="${url}" method="${type}" <%=multipart ? 'enctype="multipart/form-data"' : ''%> >

and replace:

  ${list}

with:

  <%=list%>
@sarbogast
Copy link
Owner

I didn't know about this difference between ${} and <%=%>
I'll make the change as soon as possible.

@ghost ghost assigned sarbogast May 15, 2012
@jeremydawson
Copy link
Author

I didn't know about that difference either...
This page has a good explanation:
http://alwaysthecritic.typepad.com/atc/2010/06/grails-gsp-html-escaping-confusion.html

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