Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TagLib outputs wrong encoding

I'm using a TagLib, but it is presenting a weird behaviour, instead of output character like <, ", and > it outputs &lt;, &quot;, and &gt;.

the code:

class LoginTagLib {
static defaultEncodeAs = [taglib:'html']
//static encodeAsForTags = [tagName: [taglib:'html'], otherTagName: [taglib:'none']]
def loginControl = 
{
    if(session.user)
    {
        out << "Hello ${session.user.name}"
        out << """[${link(action:"logout", controller:"user"){"Logout"}}]"""
    }
    else
    {
        out << """[${link(action:"login", controller:"user"){"Login"}}]"""
    }
}

}

in the .gsp I've got

<g:loginControl />

When I open the page I have:

Hello Jane Smith[<a href="/Blogito/user/logout">Logout</a>] 

but the page's source code is:

<div id="loginHeader">
Hello Jane Smith[&lt;a href=&quot;/Blogito/user/logout&quot;&gt;Logout&lt;/a&gt;]
</div>

I've tried using .encodeAsHTML(), decodeHTML, .replace('&gt;', '<') and nothing has worked so far

like image 259
AndersonQ Avatar asked Jul 08 '14 20:07

AndersonQ


1 Answers

Remove this line:

static defaultEncodeAs = [taglib:'html']

and try again.

like image 150
getbuckts Avatar answered Sep 18 '22 23:09

getbuckts