You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by co...@apache.org on 2021/08/03 18:29:35 UTC
svn commit: r1891990 - in /httpd/httpd/trunk: docs/manual/expr.xml
include/ap_expr.h server/util_expr_eval.c
Author: covener
Date: Tue Aug 3 18:29:35 2021
New Revision: 1891990
URL: http://svn.apache.org/viewvc?rev=1891990&view=rev
Log:
clarification/fixes around the replace() function
Modified:
httpd/httpd/trunk/docs/manual/expr.xml
httpd/httpd/trunk/include/ap_expr.h
httpd/httpd/trunk/server/util_expr_eval.c
Modified: httpd/httpd/trunk/docs/manual/expr.xml
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/docs/manual/expr.xml?rev=1891990&r1=1891989&r2=1891990&view=diff
==============================================================================
--- httpd/httpd/trunk/docs/manual/expr.xml (original)
+++ httpd/httpd/trunk/docs/manual/expr.xml Tue Aug 3 18:29:35 2021
@@ -602,7 +602,8 @@ DIGIT ::= <any US-ASCII digit "
(RFC4514) and LDAP filter escaping (RFC4515).</td><td></td></tr>
<tr><td><code>replace</code></td>
<td>replace(string, "from", "to") replaces all occurrences of "from"
- in the string with "to".</td><td></td></tr>
+ in the string with "to". The first parameter must not be a literal string.
+ </td><td></td></tr>
</table>
@@ -752,9 +753,8 @@ DIGIT ::= <any US-ASCII digit "
<If "md5('foo') == 'acbd18db4cc2f85cedef654fccc4a4d8'">
Header set checksum-matched true
</If>
-<If "md5('foo') == replace('md5:XXXd18db4cc2f85cedef654fccc4a4d8', 'md5:XXX', 'acb')">
- Header set checksum-matched-2 true
-</If>
+
+Requir expr replace(%{REQUEST_METHOD}, 'E', 'O') == 'GET'"
# Function example in string context
Header set foo-checksum "expr=%{md5:foo}"
Modified: httpd/httpd/trunk/include/ap_expr.h
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/include/ap_expr.h?rev=1891990&r1=1891989&r2=1891990&view=diff
==============================================================================
--- httpd/httpd/trunk/include/ap_expr.h (original)
+++ httpd/httpd/trunk/include/ap_expr.h Tue Aug 3 18:29:35 2021
@@ -287,8 +287,9 @@ typedef struct {
/** arg for pre-parsing (only if a simple string).
* For binary ops, this is the right argument.
- * For functions with more arguments, this is the first string
- * argument. */
+ * For AP_EXPR_FUNC_STRING functions with multiple arguments, this is the first
+ * simple/literal string argument.
+ */
const char *arg;
} ap_expr_lookup_parms;
Modified: httpd/httpd/trunk/server/util_expr_eval.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/server/util_expr_eval.c?rev=1891990&r1=1891989&r2=1891990&view=diff
==============================================================================
--- httpd/httpd/trunk/server/util_expr_eval.c (original)
+++ httpd/httpd/trunk/server/util_expr_eval.c Tue Aug 3 18:29:35 2021
@@ -286,7 +286,7 @@ static const char *ap_expr_eval_string_f
if (arg->node_op == op_ListElement) {
/* Evaluate the list elements and store them in apr_array_header. */
ap_expr_string_list_func_t *func = (ap_expr_string_list_func_t *)info->node_arg1;
- apr_array_header_t *args = ap_expr_list_make(ctx, arg->node_arg1);
+ apr_array_header_t *args = ap_expr_list_make(ctx, arg);
return (*func)(ctx, data, args);
}
else {
@@ -735,10 +735,12 @@ static ap_expr_t *ap_expr_info_make(int
parms.arg = arg->node_arg1;
break;
case op_ListElement:
+ /* save the first literal/simple string argument */
do {
const ap_expr_t *val = arg->node_arg1;
- if (val->node_op == op_String) {
+ if (val && val->node_op == op_String) {
parms.arg = val->node_arg1;
+ break;
}
arg = arg->node_arg2;
} while (arg != NULL);
@@ -1424,10 +1426,10 @@ static int replace_func_parse_arg(ap_exp
const apr_strmatch_pattern *pattern;
if (!parms->arg) {
- *parms->err = apr_psprintf(parms->ptemp, "replace() function needs "
- "exactly 3 arguments");
+ *parms->err = apr_psprintf(parms->ptemp, "replace() function needs an argument");
return !OK;
}
+
pattern = apr_strmatch_precompile(parms->pool, original, 0);
*parms->data = pattern;
return OK;
@@ -1445,13 +1447,13 @@ static const char *replace_func(ap_expr_
const apr_strmatch_pattern *pattern = data;
if (args->nelts != 3) {
*ctx->err = apr_psprintf(ctx->p, "replace() function needs "
- "exactly 3 arguments");
+ "exactly 3 arguments, got %d", args->nelts);
return "";
}
- buff = APR_ARRAY_IDX(args, 2, char *);
+ buff = APR_ARRAY_IDX(args, 0, char *);
original = APR_ARRAY_IDX(args, 1, char *);
- replacement = APR_ARRAY_IDX(args, 0, char *);
+ replacement = APR_ARRAY_IDX(args, 2, char *);
repl_len = strlen(replacement);
orig_len = strlen(original);
bytes = strlen(buff);
Re: svn commit: r1891990 - in /httpd/httpd/trunk:
docs/manual/expr.xml include/ap_expr.h server/util_expr_eval.c
Posted by Ruediger Pluem <rp...@apache.org>.
On 8/18/21 5:47 PM, Eric Covener wrote:
>> I think the first arg is passed to apr_strmatch_precompile() when the
>> expression is parsed and not at request time. I wanted to change as
>> little as possible.
>
> edit: first literal string among the arguments, since the pattern is
> not the first argument.
>
Ahh, ok that makes some sense when looking at the code, but it does not seem to make sense from a users perspective.
This seems to be only in trunk which should give us a chance to fix it.
Regards
RĂ¼diger
Re: svn commit: r1891990 - in /httpd/httpd/trunk: docs/manual/expr.xml
include/ap_expr.h server/util_expr_eval.c
Posted by Eric Covener <co...@gmail.com>.
> I think the first arg is passed to apr_strmatch_precompile() when the
> expression is parsed and not at request time. I wanted to change as
> little as possible.
edit: first literal string among the arguments, since the pattern is
not the first argument.
Re: svn commit: r1891990 - in /httpd/httpd/trunk: docs/manual/expr.xml
include/ap_expr.h server/util_expr_eval.c
Posted by Eric Covener <co...@gmail.com>.
On Wed, Aug 18, 2021 at 11:11 AM Ruediger Pluem <rp...@apache.org> wrote:
>
>
>
> On 8/3/21 8:29 PM, covener@apache.org wrote:
> > Author: covener
> > Date: Tue Aug 3 18:29:35 2021
> > New Revision: 1891990
> >
> > URL: http://svn.apache.org/viewvc?rev=1891990&view=rev
> > Log:
> > clarification/fixes around the replace() function
> >
> >
> > Modified:
> > httpd/httpd/trunk/docs/manual/expr.xml
> > httpd/httpd/trunk/include/ap_expr.h
> > httpd/httpd/trunk/server/util_expr_eval.c
> >
> > Modified: httpd/httpd/trunk/docs/manual/expr.xml
> > URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/docs/manual/expr.xml?rev=1891990&r1=1891989&r2=1891990&view=diff
> > ==============================================================================
> > --- httpd/httpd/trunk/docs/manual/expr.xml (original)
> > +++ httpd/httpd/trunk/docs/manual/expr.xml Tue Aug 3 18:29:35 2021
> > @@ -602,7 +602,8 @@ DIGIT ::= <any US-ASCII digit "
> > (RFC4514) and LDAP filter escaping (RFC4515).</td><td></td></tr>
> > <tr><td><code>replace</code></td>
> > <td>replace(string, "from", "to") replaces all occurrences of "from"
> > - in the string with "to".</td><td></td></tr>
> > + in the string with "to". The first parameter must not be a literal string.
>
> Why can't it be a literal string?
I don't totally recall, but the limitation was already present in
replace() not added here.
I think the first arg is passed to apr_strmatch_precompile() when the
expression is parsed and not at request time. I wanted to change as
little as possible.
Further multi-string arg functions probably should not follow this
pattern added created w/ replace().
Re: svn commit: r1891990 - in /httpd/httpd/trunk:
docs/manual/expr.xml include/ap_expr.h server/util_expr_eval.c
Posted by Ruediger Pluem <rp...@apache.org>.
On 8/3/21 8:29 PM, covener@apache.org wrote:
> Author: covener
> Date: Tue Aug 3 18:29:35 2021
> New Revision: 1891990
>
> URL: http://svn.apache.org/viewvc?rev=1891990&view=rev
> Log:
> clarification/fixes around the replace() function
>
>
> Modified:
> httpd/httpd/trunk/docs/manual/expr.xml
> httpd/httpd/trunk/include/ap_expr.h
> httpd/httpd/trunk/server/util_expr_eval.c
>
> Modified: httpd/httpd/trunk/docs/manual/expr.xml
> URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/docs/manual/expr.xml?rev=1891990&r1=1891989&r2=1891990&view=diff
> ==============================================================================
> --- httpd/httpd/trunk/docs/manual/expr.xml (original)
> +++ httpd/httpd/trunk/docs/manual/expr.xml Tue Aug 3 18:29:35 2021
> @@ -602,7 +602,8 @@ DIGIT ::= <any US-ASCII digit "
> (RFC4514) and LDAP filter escaping (RFC4515).</td><td></td></tr>
> <tr><td><code>replace</code></td>
> <td>replace(string, "from", "to") replaces all occurrences of "from"
> - in the string with "to".</td><td></td></tr>
> + in the string with "to". The first parameter must not be a literal string.
Why can't it be a literal string?
Regards
RĂ¼diger