From: Alan T. DeKok Date: Wed, 5 Jan 2022 21:07:30 +0000 (-0500) Subject: rename regex sub to subst X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c3d32be5e48cb7a00a468c706d47ced929614426;p=thirdparty%2Ffreeradius-server.git rename regex sub to subst --- diff --git a/src/lib/unlang/xlat_builtin.c b/src/lib/unlang/xlat_builtin.c index 6d03822b1fc..6dca280562c 100644 --- a/src/lib/unlang/xlat_builtin.c +++ b/src/lib/unlang/xlat_builtin.c @@ -2896,7 +2896,7 @@ static xlat_action_t xlat_func_strlen(TALLOC_CTX *ctx, fr_dcursor_t *out, #ifdef HAVE_REGEX_PCRE2 /** Perform regex substitution TODO CHECK * - * Called when %(sub:) pattern begins with "/" + * Called when %(subst:) pattern begins with "/" * @verbatim %(sub: //[flags] ) @@ -2907,11 +2907,11 @@ static xlat_action_t xlat_func_strlen(TALLOC_CTX *ctx, fr_dcursor_t *out, "%(sub:%{User-Name} /oo.*$/ un)" == "fun" @endverbatim * - * @see #xlat_func_sub + * @see #xlat_func_subst * * @ingroup xlat_functions */ -static xlat_action_t xlat_func_sub_regex(TALLOC_CTX *ctx, fr_dcursor_t *out, +static xlat_action_t xlat_func_subst_regex(TALLOC_CTX *ctx, fr_dcursor_t *out, UNUSED xlat_ctx_t const *xctx, request_t *request, fr_value_box_list_t *in) { @@ -2987,7 +2987,7 @@ static xlat_action_t xlat_func_sub_regex(TALLOC_CTX *ctx, fr_dcursor_t *out, #endif -static xlat_arg_parser_t const xlat_func_sub_args[] = { +static xlat_arg_parser_t const xlat_func_subst_args[] = { { .required = true, .concat = true, .type = FR_TYPE_STRING }, { .required = true, .concat = true, .type = FR_TYPE_STRING }, { .required = true, .concat = true, .type = FR_TYPE_STRING }, @@ -3005,11 +3005,11 @@ static xlat_arg_parser_t const xlat_func_sub_args[] = { "%(sub:%{User-Name} oo un)" == "funbar" @endverbatim * - * @see xlat_func_sub_regex + * @see xlat_func_subst_regex * * @ingroup xlat_functions */ -static xlat_action_t xlat_func_sub(TALLOC_CTX *ctx, fr_dcursor_t *out, +static xlat_action_t xlat_func_subst(TALLOC_CTX *ctx, fr_dcursor_t *out, #ifdef HAVE_REGEX_PCRE2 xlat_ctx_t const *xctx, #else @@ -3031,7 +3031,7 @@ static xlat_action_t xlat_func_sub(TALLOC_CTX *ctx, fr_dcursor_t *out, if (*pattern == '/') { #ifdef HAVE_REGEX_PCRE2 - return xlat_func_sub_regex(ctx, out, xctx, request, in); + return xlat_func_subst_regex(ctx, out, xctx, request, in); #else REDEBUG("regex based substitutions require libpcre2. " "Check ${features.regex-pcre2} to determine support"); @@ -3604,7 +3604,7 @@ do { \ XLAT_REGISTER_ARGS("debug_attr", xlat_func_debug_attr, xlat_func_debug_attr_args); XLAT_REGISTER_ARGS("nexttime", xlat_func_next_time, xlat_func_next_time_args); XLAT_REGISTER_ARGS("pairs", xlat_func_pairs, xlat_func_pairs_args); - XLAT_REGISTER_ARGS("sub", xlat_func_sub, xlat_func_sub_args); + XLAT_REGISTER_ARGS("subst", xlat_func_subst, xlat_func_subst_args); XLAT_REGISTER_ARGS("trigger", trigger_xlat, trigger_xlat_args); xlat_register(NULL, "untaint", xlat_func_untaint, NULL); diff --git a/src/tests/keywords/xlat-sub b/src/tests/keywords/xlat-subst similarity index 53% rename from src/tests/keywords/xlat-sub rename to src/tests/keywords/xlat-subst index 239eeb3729f..6ce20358a25 100644 --- a/src/tests/keywords/xlat-sub +++ b/src/tests/keywords/xlat-subst @@ -12,68 +12,68 @@ update request { # # Global substitution -if ("%(sub:%{Tmp-String-0} a b)" != 'bbb') { +if ("%(subst:%{Tmp-String-0} a b)" != 'bbb') { test_fail } # No match -if ("%(sub:%{Tmp-String-0} c b)" != 'aaa') { +if ("%(subst:%{Tmp-String-0} c b)" != 'aaa') { test_fail } # Line ending rewrite -if ("%(sub:%{Tmp-String-1} \n \r)" != "\r\r\r") { +if ("%(subst:%{Tmp-String-1} \n \r)" != "\r\r\r") { test_fail } # Removal -if ("%(sub:%{Tmp-String-0} a '')" != "") { +if ("%(subst:%{Tmp-String-0} a '')" != "") { test_fail } # Removal of last word only -if ("%(sub:%{Tmp-String-2} dog '')" != "the quick brown fox jumped over the lazy ") { +if ("%(subst:%{Tmp-String-2} dog '')" != "the quick brown fox jumped over the lazy ") { test_fail } # Removal of first and subsequent word -if ("%(sub:%{Tmp-String-2} the '')" != " quick brown fox jumped over lazy dog") { +if ("%(subst:%{Tmp-String-2} the '')" != " quick brown fox jumped over lazy dog") { test_fail } # Removal of middle word -if ("%(sub:%{Tmp-String-2} jumped '')" != "the quick brown fox over the lazy dog") { +if ("%(subst:%{Tmp-String-2} jumped '')" != "the quick brown fox over the lazy dog") { test_fail } # Replacement of last word only -if ("%(sub:%{Tmp-String-2} dog cat)" != "the quick brown fox jumped over the lazy cat") { +if ("%(subst:%{Tmp-String-2} dog cat)" != "the quick brown fox jumped over the lazy cat") { test_fail } # Replacement of first and subsequent word -if ("%(sub:%{Tmp-String-2} the cat)" != "cat quick brown fox jumped over cat lazy dog") { +if ("%(subst:%{Tmp-String-2} the cat)" != "cat quick brown fox jumped over cat lazy dog") { test_fail } # Replacement of middle word -if ("%(sub:%{Tmp-String-2} jumped cat)" != "the quick brown fox cat over the lazy dog") { +if ("%(subst:%{Tmp-String-2} jumped cat)" != "the quick brown fox cat over the lazy dog") { test_fail } if ("${feature.regex-pcre2}" == 'yes') { # Basic substitutions -if ("%(sub:%{Tmp-String-0} /a/ b)" != 'baa') { +if ("%(subst:%{Tmp-String-0} /a/ b)" != 'baa') { test_fail } # Global substitution -if ("%(sub:%{Tmp-String-0} /a/g b)" != 'bbb') { +if ("%(subst:%{Tmp-String-0} /a/g b)" != 'bbb') { test_fail } # No match -if ("%(sub:%{Tmp-String-0} /z/ b)" != 'aaa') { +if ("%(subst:%{Tmp-String-0} /z/ b)" != 'aaa') { test_fail } @@ -87,26 +87,26 @@ if ("%(length:%{Tmp-String-1})" != 3) { } # Strip out just the first newline -if ("%(sub:%{Tmp-String-1} /^./s '')" != "\n\n") { +if ("%(subst:%{Tmp-String-1} /^./s '')" != "\n\n") { test_fail } -if ("%(sub:%{Tmp-String-1} /\n/ '')" != "\n\n") { +if ("%(subst:%{Tmp-String-1} /\n/ '')" != "\n\n") { test_fail } # Strip out all the newlines -if ("%(sub:%{Tmp-String-1} /\n/g '')" != '') { +if ("%(subst:%{Tmp-String-1} /\n/g '')" != '') { test_fail } # Line ending switch -if ("%(sub:%{Tmp-String-1} /\n/g \r)" != "\r\r\r") { +if ("%(subst:%{Tmp-String-1} /\n/g \r)" != "\r\r\r") { test_fail } # Bad regex -if ("%(sub:%{Tmp-String-0} /***/g .)") { +if ("%(subst:%{Tmp-String-0} /***/g .)") { test_fail } @@ -119,7 +119,7 @@ update request { } # Empty regex -if ("%(sub:%{Tmp-String-0} //g .)") { +if ("%(subst:%{Tmp-String-0} //g .)") { test_fail }