From: Alan T. DeKok Date: Sat, 26 Apr 2025 16:47:33 +0000 (-0400) Subject: rename subst -> str.subst X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=83536614acbdf1f9c08a33c25b938d98b506710d;p=thirdparty%2Ffreeradius-server.git rename subst -> str.subst --- diff --git a/doc/antora/modules/reference/pages/xlat/builtin.adoc b/doc/antora/modules/reference/pages/xlat/builtin.adoc index 0fd6d3b7c3..31bd919b11 100644 --- a/doc/antora/modules/reference/pages/xlat/builtin.adoc +++ b/doc/antora/modules/reference/pages/xlat/builtin.adoc @@ -172,9 +172,9 @@ reply.Reply-Message := "You should wait for %nexttime(1h)s" You should wait for 2520s ``` -### %sub(, //[flags], ) +### %str.subst(, , ) -Substitute text just as easily as it can match it, even using regex patterns. +Substitute text. .Return: _string_. diff --git a/src/lib/unlang/xlat_builtin.c b/src/lib/unlang/xlat_builtin.c index 42c5776b1e..87055dd5ff 100644 --- a/src/lib/unlang/xlat_builtin.c +++ b/src/lib/unlang/xlat_builtin.c @@ -4280,10 +4280,17 @@ do { \ XLAT_REGISTER_ARGS("log.destination", xlat_func_log_dst, FR_TYPE_STRING, xlat_func_log_dst_args); XLAT_REGISTER_ARGS("nexttime", xlat_func_next_time, FR_TYPE_UINT64, xlat_func_next_time_args); XLAT_REGISTER_ARGS("pairs", xlat_func_pairs, FR_TYPE_STRING, xlat_func_pairs_args); + + XLAT_REGISTER_ARGS("str.subst", xlat_func_subst, FR_TYPE_STRING, xlat_func_subst_args); +#ifdef HAVE_REGEX_PCRE2 + xlat_func_instantiate_set(xlat, xlat_instantiate_subst_regex, xlat_subst_regex_inst_t, NULL, NULL); +#endif XLAT_REGISTER_ARGS("subst", xlat_func_subst, FR_TYPE_STRING, xlat_func_subst_args); + XLAT_NEW("str.subst"); #ifdef HAVE_REGEX_PCRE2 xlat_func_instantiate_set(xlat, xlat_instantiate_subst_regex, xlat_subst_regex_inst_t, NULL, NULL); #endif + XLAT_REGISTER_ARGS("time", xlat_func_time, FR_TYPE_VOID, xlat_func_time_args); XLAT_REGISTER_ARGS("trigger", trigger_xlat, FR_TYPE_STRING, trigger_xlat_args); XLAT_REGISTER_ARGS("base64.encode", xlat_func_base64_encode, FR_TYPE_STRING, xlat_func_base64_encode_arg); diff --git a/src/tests/keywords/radius.conf b/src/tests/keywords/radius.conf index 789c1a382b..02902ff2e4 100644 --- a/src/tests/keywords/radius.conf +++ b/src/tests/keywords/radius.conf @@ -10,7 +10,7 @@ modules { } delay delay_10s { - delay = "%{10 + Tmp-String-0}" + delay = 10 } # diff --git a/src/tests/keywords/xlat-subst b/src/tests/keywords/xlat-subst index 249e34e340..8a6b4365f2 100644 --- a/src/tests/keywords/xlat-subst +++ b/src/tests/keywords/xlat-subst @@ -13,78 +13,78 @@ empty_string := '' # # Global substitution -if (!(%subst(test_string1, 'a', 'b') == 'bbb')) { +if (!(%str.subst(test_string1, 'a', 'b') == 'bbb')) { test_fail } # No match -if (!(%subst(test_string1, 'c', 'b') == 'aaa')) { +if (!(%str.subst(test_string1, 'c', 'b') == 'aaa')) { test_fail } # Line ending rewrite -if (!(%subst(test_string2, "\n", "\r") == "\r\r\r")) { +if (!(%str.subst(test_string2, "\n", "\r") == "\r\r\r")) { test_fail } # Removal -if (!(%subst(test_string1, 'a', '') == "")) { +if (!(%str.subst(test_string1, 'a', '') == "")) { test_fail } # Removal of last word only -if (!(%subst(test_string3, 'dog', '') == "the quick brown fox jumped over the lazy ")) { +if (!(%str.subst(test_string3, 'dog', '') == "the quick brown fox jumped over the lazy ")) { test_fail } # Removal of first and subsequent word -if (!(%subst(test_string3, 'the', '') == " quick brown fox jumped over lazy dog")) { +if (!(%str.subst(test_string3, 'the', '') == " quick brown fox jumped over lazy dog")) { test_fail } # Removal of middle word -if (!(%subst(test_string3, 'jumped', '') == "the quick brown fox over the lazy dog")) { +if (!(%str.subst(test_string3, 'jumped', '') == "the quick brown fox over the lazy dog")) { test_fail } # Replacement of last word only -if (!(%subst(test_string3, 'dog', 'cat') == "the quick brown fox jumped over the lazy cat")) { +if (!(%str.subst(test_string3, 'dog', 'cat') == "the quick brown fox jumped over the lazy cat")) { test_fail } # Replacement of first and subsequent word -if (!(%subst(test_string3, 'the', 'cat') == "cat quick brown fox jumped over cat lazy dog")) { +if (!(%str.subst(test_string3, 'the', 'cat') == "cat quick brown fox jumped over cat lazy dog")) { test_fail } # Replacement of middle word -if (!(%subst(test_string3, 'jumped', 'cat') == "the quick brown fox cat over the lazy dog")) { +if (!(%str.subst(test_string3, 'jumped', 'cat') == "the quick brown fox cat over the lazy dog")) { test_fail } if ("${feature.regex-pcre2}" == 'yes') { # Basic substitutions -if (!(%subst(test_string1, '/a/', 'b') == 'baa')) { +if (!(%str.subst(test_string1, '/a/', 'b') == 'baa')) { test_fail } # Global substitution -if (!(%subst(test_string1, '/a/g', 'b') == 'bbb')) { +if (!(%str.subst(test_string1, '/a/g', 'b') == 'bbb')) { test_fail } # No match -if (!(%subst(test_string1, '/z/', 'b') == 'aaa')) { +if (!(%str.subst(test_string1, '/z/', 'b') == 'aaa')) { test_fail } # Basic substitutions - Dynamic -if (!(%subst(test_string1, "/a%{empty_string}/", 'b') == 'baa')) { +if (!(%str.subst(test_string1, "/a%{empty_string}/", 'b') == 'baa')) { test_fail } # Global substitution - Dynamic -if (!(%subst(test_string1, "/a%{empty_string}/g", 'b') == 'bbb')) { +if (!(%str.subst(test_string1, "/a%{empty_string}/g", 'b') == 'bbb')) { test_fail } @@ -98,30 +98,30 @@ if (!(%length(test_string2) == 3)) { } # Strip out just the first newline -if (!(%subst(test_string2, '/^./s', '') == "\n\n")) { +if (!(%str.subst(test_string2, '/^./s', '') == "\n\n")) { test_fail } -if (!(%subst(test_string2, '/\n/', '') == "\n\n")) { +if (!(%str.subst(test_string2, '/\n/', '') == "\n\n")) { test_fail } # Strip out all the newlines -if (!(%subst(test_string2, '/\n/g', '') == '')) { +if (!(%str.subst(test_string2, '/\n/g', '') == '')) { test_fail } # Line ending switch -if (!(%subst(test_string2, '/\n/g', "\r") == "\r\r\r")) { +if (!(%str.subst(test_string2, '/\n/g', "\r") == "\r\r\r")) { test_fail } # Capture groups -if (!(%subst(test_string3, '/^the (.*) brown (.*) jumped.*/', "$1,$2") == "quick,fox")) { +if (!(%str.subst(test_string3, '/^the (.*) brown (.*) jumped.*/', "$1,$2") == "quick,fox")) { test_fail } -if (!(%subst(test_string3, "/^%{empty_string}the (.*) brown (.*) jumped.*/", "$1,$2") == "quick,fox")) { +if (!(%str.subst(test_string3, "/^%{empty_string}the (.*) brown (.*) jumped.*/", "$1,$2") == "quick,fox")) { test_fail } diff --git a/src/tests/keywords/xlat-subst-error-empty-patt b/src/tests/keywords/xlat-subst-error-empty-patt index adc2493bb6..46e10b1737 100644 --- a/src/tests/keywords/xlat-subst-error-empty-patt +++ b/src/tests/keywords/xlat-subst-error-empty-patt @@ -1,4 +1,4 @@ # Empty regex -if (%subst(%{test_string1}, //g, '.')) { # ERROR +if (%str.subst(%{test_string1}, //g, '.')) { # ERROR test_fail } diff --git a/src/tests/keywords/xlat-subst-error-patt b/src/tests/keywords/xlat-subst-error-patt index 5774f730b7..953523625f 100644 --- a/src/tests/keywords/xlat-subst-error-patt +++ b/src/tests/keywords/xlat-subst-error-patt @@ -1,4 +1,4 @@ # Bad regex -if (%subst(%{test_string1}, /***/g, '.')) { #ERROR +if (%str.subst(%{test_string1}, /***/g, '.')) { #ERROR test_fail }