You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Christopher Schultz <ch...@christopherschultz.net> on 2013/07/01 17:59:51 UTC

Re: SSI - Regular expression parsing

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

David,

On 6/28/13 7:40 PM, David Reitter wrote:
> I'm trying to use some SSI in 7.0.39 using SSIFilter.  The file is
> parsed, in principle, but whenever an IF expression with a certain
> regular expression is encountered, Tomcat seems to stop processing
> the file and will not return any contents after that (for the
> request).
> 
> Example:
> 
> My request is:
> 
> http://...:8080/amt/file.html?year=234234
> 
> 
> The relevant portion of the file is:
> 
> 
> QS:<!--#echo var="QUERY_STRING" -->
> 
> <!--#if expr="${QUERY_STRING} = /year=(.*)/" --> <!--ssi-comment:
> year found --> <!--#set var="year" value="$1" --> year: <!--#echo
> var="year" -->
> 
> <!--#else --> not <!--ssi-comment: year NOT found --> <!--#set
> var="year" value="some" --> <!--#endif -->
> 
> 
> 
> The response to the request is the beginning of the file, and then
> 
> QS:year=2012
> 
> After the "#if", nothing is encountered.

This is due to the error shown below. Thanks for locating it and
reporting it along with your post: often, we have to have a whole
round trip of "look at the longs", etc. before we can figure out
what's going on.

> Other IF statements work as expected - this seems to have to do
> with the regular expression.
> 
> I have tried a number of variants, including $QUERY_STRING instead
> of ${...}. I find no error about this in the logs (I have set debug
> to 1 for the SSIFilter, but I'm not sure if I need to change
> anything else in logging properties.
> 
> I tried simpler regular expressions.  The following
> 
> <!--#if expr="${QUERY_STRING} = /year=/" -->
> 
> Leads to the error below:
> 
> java.lang.ClassCastException:
> org.apache.catalina.ssi.ExpressionParseTree$EqualNode cannot be
> cast to org.apache.catalina.ssi.ExpressionParseTree$StringNode 
> org.apache.catalina.ssi.ExpressionParseTree$CompareNode.compareBranches(ExpressionParseTree.java:353)
>
> 
org.apache.catalina.ssi.ExpressionParseTree$EqualNode.evaluate(ExpressionParseTree.java:381)
> org.apache.catalina.ssi.ExpressionParseTree.evaluateTree(ExpressionParseTree.java:67)
>
> 
org.apache.catalina.ssi.SSIConditional.evaluateArguments(SSIConditional.java:124)
> org.apache.catalina.ssi.SSIConditional.process(SSIConditional.java:50)
>
> 
org.apache.catalina.ssi.SSIProcessor.process(SSIProcessor.java:160)
> org.apache.catalina.ssi.SSIFilter.doFilter(SSIFilter.java:144)
> 
> 
> This occurs whenever the regular expression does not contain any
> parenthesis.  Is it even recognized/parsed as a regexp?
> 
> 
> Is this a bug, or is my syntax off?  I follow
> http://tomcat.apache.org/tomcat-6.0-doc/ssi-howto.html

Although it does not matter in this case (because the documentation is
pretty much identical), you should probably be reading this document
instead:

http://tomcat.apache.org/tomcat-7.0-doc/ssi-howto.html

Can you provide a minimal test case as a WAR file: basically just the
META-INF/web.xml and a minimal SSI page to be processed?

It's very odd that the left-branch of the expression is being treated
as an "equal" node... my first guess at this point is that
${QUERY_STRING} is being interpreted /twice/ -- once as the variable
reference, then converted into its own value and possibly
re-interpreted? That would result in the expression "year=234234 =
/year=(.)/" which would make the left-expression "year=234234" which
would be an EqualNode. It really doesn't make any sense as people must
be doing this kind of thing all the time and we haven't heard any
complaints recently.

On the other hand, I think Tomcat's SSIs are quite rarely used.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIcBAEBCAAGBQJR0ad3AAoJEBzwKT+lPKRYCPEP/ifA9uk7wlN8DekKRceCBWUu
a0U2WQUd11HerG7oh65niv65VYLKFaRwTIAknFG2hTgA/Jk+TR3zSqXxa34V5Ahq
AbTceyLbp9cN11U4ziBMDB77XhLXeS3mQ5cF0780lShgzJlCekeZF/KxeLhaaXS2
/eQ4mIi5322cn8UhEItNEnhm4MdjFTdZ39IPFUXZerEfA7P6omAJG59H6HZOet8O
oMw9IasGv/Kr4vazndHrRWaDkfvnbQTgJMfuLAKXuTGLyqcrzQfpic4gRKiaPxQL
WIdHQRngy2SmmgmHKkEitsc6+ZhQaCfB2Lz/syVRib9bXd/6qRC7xbXAaLRw3sSU
QlsSIBg+zCB2s+2VMWjuDiAH2wIQQ+vvLJcxFHCNkliopmqqD04ZeXrUKol2s9KI
w/B9hBVwtKiFhi1yUiKmcVOv1p8SdxDYbdiqsSupotAiA17l14SOhzbcjicNr9hv
/Hm4gZ4qTbbs8x4uEWU5tpm91tbrmbz6UM+B9cWVa2WmqC784W19h+X/k+plZYdT
7zzH0O0yAK6mLXhgmqeooRThRejGaClYaT+eqlJE7hg4T7dhBURC2AYDl5mi9YRS
R7wzN9jkthBtuEdalDdyMtXszundLUlIMBz/wc8e8iMKi0ihTgMk0Ivqyivdt2fl
n2kGJW88/k386GD7kVD5
=2HT/
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org