3

Using Apache 2.4.10 (ap_expr in no legacy mode), the following SSI does not return the expected capturing group:

<!--#set var="keyvaluepair" value="key1=value1" -->
<!--#if expr="v('keyvaluepair')=~/key1=([a-zA-Z0-9]*)/" -->
<!--#set var="match" value="$0" -->
<!--#set var="value" value="$1" -->
<!--#endif -->

keyvaluepair:<!--#echo var="keyvaluepair" -->
<br>regex: /key1=([a-zA-Z0-9]*)/
<br>match:<!--#echo var="match" -->
<br>value:<!--#echo var="value" -->
<br>expected value: value1
<br>Why is $1 empty?

Because of parenthesis around [a-zA-Z0-9]* in the regular expression, I would expect $1 to be just that capturing group, which should be the value only. Why is that empty?

Olaf

Edit: $1 seems only to work in legacy mode (SSILegacyExprParser on), using $ instead of v() function, (?:^|&) instead of \b and not using =~:

<!--#if expr="$keyvaluepair = /(?:^|&)key1=([a-zA-Z0-9]*)/" -->

Is there perhaps a change in how to mark/delimit capturing groups in the newer ap_expr syntax?

  • I was just looking into the same issue, seems like I also need to enable SSILegacyExprParser or is someone aware this got fixed nowadays? The weird thing is I can see it being referenced at: https://httpd.apache.org/docs/2.4/expr.html other section – Jdruwe Apr 14 '23 at 08:39

1 Answers1

0

There indeed seems to be an issue when combining ap_expr and ssi. People bumping into this issue in the future, take a look at the 'fix' from Helge at https://bz.apache.org/bugzilla/show_bug.cgi?id=57448

Jdruwe
  • 3,450
  • 6
  • 36
  • 57