[2.0] scala template encoding

356 views
Skip to first unread message

Roman Bykovskiy

unread,
Mar 15, 2012, 5:42:33 AM3/15/12
to play-fr...@googlegroups.com
When I check source code of page made by scala template in browser I see text encoded like this: Стол № - why?

Yan A

unread,
Mar 16, 2012, 9:03:53 AM3/16/12
to play-fr...@googlegroups.com
and if string hardcoded in template "пример" - it outputs correctly,
if from @obj.prop - outputs like $#xxxx;

Yan A

unread,
Mar 16, 2012, 9:45:48 AM3/16/12
to play-fr...@googlegroups.com
Pramework always calls  

org.apache.commons.lang.StringEscapeUtils.escapeHtml(text) 

for any string passed to template engine to output

Yan A

unread,
Mar 16, 2012, 9:58:43 AM3/16/12
to play-fr...@googlegroups.com
Apache's escape is very straitforward - escapes all non-asci.

    public void escape(Writer writer, String str) throws IOException {
        int len = str.length();
        for (int i = 0; i < len; i++) {
            char c = str.charAt(i);
            String entityName = this.entityName(c);
            if (entityName == null) {
                if (c > 0x7F) {
                    writer.write("&#");
                    writer.write(Integer.toString(c, 10));
                    writer.write(';');
                } else {
                    writer.write(c);
                }
            } else {
                writer.write('&');
                writer.write(entityName);
                writer.write(';');

Freewind

unread,
Mar 16, 2012, 10:07:15 AM3/16/12
to play-fr...@googlegroups.com
You can use @Html(xxx) instead of @xxx to tell play2 not encode them

Roman Bykovskiy

unread,
Mar 16, 2012, 10:19:01 AM3/16/12
to play-fr...@googlegroups.com
But it's complicated to put every variable in wrapper and also what if I need to escape html tags but not to escape alph chars?

пятница, 16 марта 2012 г. 18:07:15 UTC+4 пользователь Freewind написал:
Reply all
Reply to author
Forward
0 new messages