#ifdef HAVE_REGEX_PCRE2
/** Perform regex substitution TODO CHECK
*
- * Called when %(sub:) pattern begins with "/"
+ * Called when %(subst:) pattern begins with "/"
*
@verbatim
%(sub:<subject> /<regex>/[flags] <replace>)
"%(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)
{
#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 },
"%(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
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");
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);
#
# 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
}
}
# 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
}
}
# Empty regex
-if ("%(sub:%{Tmp-String-0} //g .)") {
+if ("%(subst:%{Tmp-String-0} //g .)") {
test_fail
}