]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
rename subst -> str.subst
authorAlan T. DeKok <aland@freeradius.org>
Sat, 26 Apr 2025 16:47:33 +0000 (12:47 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Sat, 26 Apr 2025 19:44:09 +0000 (15:44 -0400)
doc/antora/modules/reference/pages/xlat/builtin.adoc
src/lib/unlang/xlat_builtin.c
src/tests/keywords/radius.conf
src/tests/keywords/xlat-subst
src/tests/keywords/xlat-subst-error-empty-patt
src/tests/keywords/xlat-subst-error-patt

index 0fd6d3b7c3b91eff4e33a175d5240ab46537bee7..31bd919b11cd0bf925aca6ccd9e9fdd42eb7721e 100644 (file)
@@ -172,9 +172,9 @@ reply.Reply-Message := "You should wait for %nexttime(1h)s"
 You should wait for 2520s
 ```
 
-### %sub(<subject>, /<regex>/[flags], <replace>)
+### %str.subst(<subject>, <find>, <replace>)
 
-Substitute text just as easily as it can match it, even using regex patterns.
+Substitute text.
 
 .Return: _string_.
 
index 42c5776b1eda8a4e4e69d4c22b6aa5cf3eba519a..87055dd5ff1dfa1dfa8cf8740fde5f4e5815e96d 100644 (file)
@@ -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);
index 789c1a382bd25c163dccc1aaeb350942a52bb31e..02902ff2e40665575d5aa9dcd23b8ef497848c2b 100644 (file)
@@ -10,7 +10,7 @@ modules {
        }
 
        delay delay_10s {
-               delay = "%{10 + Tmp-String-0}"
+               delay = 10
        }
 
        #
index 249e34e340a8606d52b7b054e1817f58f9fcfc5f..8a6b4365f27eaa7b6603b46bfc8d52dc3f9ee459 100644 (file)
@@ -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
 }
 
index adc2493bb6efc4756f3abe02a051fe57b890d928..46e10b1737c02dd4fb424aaab7eceeaf9e8d17cf 100644 (file)
@@ -1,4 +1,4 @@
 # Empty regex
-if (%subst(%{test_string1}, //g, '.')) { # ERROR
+if (%str.subst(%{test_string1}, //g, '.')) { # ERROR
        test_fail
 }
index 5774f730b78634375ad67e35e883de99121f83e5..953523625f948b876e9238d419a42c4dbe87035a 100644 (file)
@@ -1,4 +1,4 @@
 # Bad regex
-if (%subst(%{test_string1}, /***/g, '.')) { #ERROR
+if (%str.subst(%{test_string1}, /***/g, '.')) { #ERROR
        test_fail
 }