]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
%regex() -> %regex.match()
authorAlan T. DeKok <aland@freeradius.org>
Tue, 29 Apr 2025 14:29:18 +0000 (10:29 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 29 Apr 2025 14:29:18 +0000 (10:29 -0400)
doc/antora/modules/reference/pages/unlang/condition/regex.adoc
doc/antora/modules/reference/pages/xlat/builtin.adoc
src/lib/unlang/xlat_builtin.c
src/tests/keywords/if-failed-xlat
src/tests/keywords/if-regex-match-named

index a9bcaac70844e91ff28b1a6b1e1c0d57331ad46a..848370c97f44edb57c4015adbdc35e066deaf454 100644 (file)
@@ -119,7 +119,7 @@ matched. The expansions +
 
 When using libpcre[2], named capture groups may also be accessed using the
 built-in expansion +
-`%regex(<named capture group>)`.
+`%regex.match(<named capture group>)`.
 
 Please see the xref:xlat/builtin.adoc#_0_32[xlat documentation] for
 more information on regular expression matching.
index 31bd919b11cd0bf925aca6ccd9e9fdd42eb7721e..80a205624a00935c21cfc203df707f9d5c5fab57 100644 (file)
@@ -92,11 +92,11 @@ groups in the pattern.
 Every time a regular expression is evaluated, whether it matches or not,
 the numbered capture group values will be cleared.
 
-=== +%regex(<named capture group>}+
+=== +%regex.match(<named capture group>}+
 
 Return named subcapture value from the last regular expression evaluated.
 
-Results of named capture groups are available using the `%regex(<named capture
+Results of named capture groups are available using the `%regex.match(<named capture
 group>}` expansion. They will also be accessible using the numbered expansions
 described xref:xlat/builtin.adoc#_0_32[above].
 
index 87055dd5ff1dfa1dfa8cf8740fde5f4e5815e96d..00a85488d9f2b98247f55b16da866946d48ff18f 100644 (file)
@@ -2792,7 +2792,7 @@ static xlat_arg_parser_t const xlat_func_regex_args[] = {
 if ("foo" =~ /^(?<name>.*)/) {
         noop
 }
-%regex(name) == "foo"
+%regex.match(name) == "foo"
 @endverbatim
  *
  * @ingroup xlat_functions
@@ -4333,9 +4333,13 @@ do { \
        XLAT_NEW("hash.md4");
 
 #if defined(HAVE_REGEX_PCRE) || defined(HAVE_REGEX_PCRE2)
+       if (unlikely((xlat = xlat_func_register(xlat_ctx, "regex.match", xlat_func_regex, FR_TYPE_STRING)) == NULL)) return -1;
+       xlat_func_args_set(xlat, xlat_func_regex_args);
+       xlat_func_flags_set(xlat, XLAT_FUNC_FLAG_INTERNAL);
        if (unlikely((xlat = xlat_func_register(xlat_ctx, "regex", xlat_func_regex, FR_TYPE_STRING)) == NULL)) return -1;
        xlat_func_args_set(xlat, xlat_func_regex_args);
        xlat_func_flags_set(xlat, XLAT_FUNC_FLAG_INTERNAL);
+       XLAT_NEW("regex.match");
 #endif
 
        {
index 420b55d9bf6f12a0d5fccd8550bdc356825446c9..495d8bed59ecf34182f6e4fada3a80fec331c670 100644 (file)
@@ -6,7 +6,7 @@ if (('${feature.regex-pcre}' == 'yes') || ('${feature.regex-pcre2}' == 'yes')) {
 
 # Check failure when no previous capture - named group
 # but a failed regex is equivalent to an empty string
-if (%regex('foo')) {
+if (%regex.match('foo')) {
        test_fail
 }
 
index 714f4e8f8aa03f18d705c013d330cf9f96bee0b6..e86a52a0366ba316429ce308975905b36e15cc9f 100644 (file)
@@ -10,7 +10,7 @@ if (('${feature.regex-pcre}' == 'yes') || ('${feature.regex-pcre2}' == 'yes')) {
        }
 
 # Check failure when no previous capture - full capture
-if (%regex()) {
+if (%regex.match()) {
        test_fail
 }
 
@@ -21,7 +21,7 @@ if (!(Module-Failure-Message[*] == "No previous regex capture")) {
 request -= Module-Failure-Message[*]
 
 # Check failure when no previous capture - named group
-if (%regex('foo')) {
+if (%regex.match('foo')) {
        test_fail
 }
 
@@ -32,7 +32,7 @@ if (!(Module-Failure-Message[*] == "No previous named regex capture group 'foo'"
 request -= Module-Failure-Message[*]
 
 # Check failure when no previous capture - numbered group
-if (%regex(Port-Limit)) {
+if (%regex.match(Port-Limit)) {
        test_fail
 }
 
@@ -44,7 +44,7 @@ request -= Module-Failure-Message[*]
 
 # uncompiled - ref - named capture groups
 if (User-Name =~ /^(?<one>[0-9])_(?<two>[0-9])?_(?<three>[0-9]*)_(?<four>[0-9]+)_(?<five>[^_])_(?<six>6)_(?<seven>[7-8])%{dummy_string}/) {
-       result_string := "%regex('seven')_%regex('six')_%regex('five')_%regex('four')_%regex('three')_%regex('two')_%regex('one')_%{0}"
+       result_string := "%regex.match('seven')_%regex.match('six')_%regex.match('five')_%regex.match('four')_%regex.match('three')_%regex.match('two')_%regex.match('one')_%{0}"
        if (!(result_string == '7_6_5_4_3_2_1_1_2_3_4_5_6_7')) {
                test_fail
        }
@@ -55,7 +55,7 @@ else {
 
 # Checking capture groups are cleared out correctly
 if (User-Name =~ /^(?<one>[0-9])_%{dummy_string}/) {
-       result_string := "%{0}%regex('one')%regex('two')%regex('three')%regex('four')%regex('five')%regex('six')%regex('seven')"
+       result_string := "%{0}%regex.match('one')%regex.match('two')%regex.match('three')%regex.match('four')%regex.match('five')%regex.match('six')%regex.match('seven')"
        if (!(result_string == '1_1')) {
                test_fail
        }
@@ -66,7 +66,7 @@ else {
 
 # Checking capture groups are cleared out correctly when there are no matches
 if (User-Name =~ /^.%{dummy_string}/) {
-       result_string := "%{0}%regex('one')%regex('two')%regex('three')%regex('four')%regex('five')%regex('six')%regex('seven')"
+       result_string := "%{0}%regex.match('one')%regex.match('two')%regex.match('three')%regex.match('four')%regex.match('five')%regex.match('six')%regex.match('seven')"
        if (!(result_string == '1')) {
                test_fail
        }
@@ -77,7 +77,7 @@ else {
 
 # compiled - ref - named capture groups
 if (User-Name =~ /^(?<one>[0-9])_(?<two>[0-9])?_(?<three>[0-9]*)_(?<four>[0-9]+)_(?<five>[^_])_(?<six>6)_(?<seven>[7-8])/) {
-       result_string := "%regex('seven')_%regex('six')_%regex('five')_%regex('four')_%regex('three')_%regex('two')_%regex('one')_%{0}"
+       result_string := "%regex.match('seven')_%regex.match('six')_%regex.match('five')_%regex.match('four')_%regex.match('three')_%regex.match('two')_%regex.match('one')_%{0}"
        if (!(result_string == '7_6_5_4_3_2_1_1_2_3_4_5_6_7')) {
                test_fail
        }
@@ -88,7 +88,7 @@ else {
 
 # compiled - xlat - named capture groups
 if ('1_2_3_4_5_6_7' =~ /^(?<one>[0-9])_(?<two>[0-9])?_(?<three>[0-9]*)_(?<four>[0-9]+)_(?<five>[^_])_(?<six>6)_(?<seven>[7-8])/) {
-       result_string := "%regex('seven')_%regex('six')_%regex('five')_%regex('four')_%regex('three')_%regex('two')_%regex('one')_%{0}"
+       result_string := "%regex.match('seven')_%regex.match('six')_%regex.match('five')_%regex.match('four')_%regex.match('three')_%regex.match('two')_%regex.match('one')_%{0}"
        if (!(result_string == '7_6_5_4_3_2_1_1_2_3_4_5_6_7')) {
                test_fail
        }
@@ -128,7 +128,7 @@ if (User-Name =~ /^(?<one>[0-9])_(?<two>[0-9])?_(?<three>[0-9]*)_(?<four>[0-9]+)
        g := 6
        h := 7
 
-       result_string := "%regex(h)_%regex(g)_%regex(f)_%regex(e)_%regex(d)_%regex(c)_%regex(b)_%regex(a)"
+       result_string := "%regex.match(h)_%regex.match(g)_%regex.match(f)_%regex.match(e)_%regex.match(d)_%regex.match(c)_%regex.match(b)_%regex.match(a)"
        if (!(result_string == '7_6_5_4_3_2_1_1_2_3_4_5_6_7')) {
                test_fail
        }