views:

205

answers:

1

I just stumbled unto a weirdness in my JSP code. It seems that a double backslash followed by a dollar or percent symbol gets converted to a single backslash (plus symbol).

That is, the following JSP:

<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" %>
\\#
\\$
\\%
\\^

gets rendered as:

\\#
\$
\%
\\^

I'm using JDK 1.6.0_02 and Apache Tomcat 5.5.23 and 6.0.16 (two machines).

Is this a bug in Tomcat? JDK? Or is it conforming to some obscure option in the JSP spec? I tried looking at the spec but couldn't find anything useful.

Workarounds are fairly trivial, I just thought I'd file a bug in case it is one.

EDIT: Heh, stackoverflow also mangles backslashes

+1  A: 

\$ is in the spec (Section JSP.1.6). "Only when EL is enabled for the page...., a literal $ can be quoted by \$.

\% will probably be because "A literal <% is quoted by <\%". I suspect that the parser isn't checking for the < before the \%.

davidsheldon