fr_sbuff_next(in);
if (!fr_sbuff_next_if_char(in, ')')) {
- fr_strerror_const("Missing ')'");
+ fr_strerror_const("Missing closing brace ')'");
return -1;
}
node->call.input_type = func->input_type;
}
+ fr_sbuff_marker_release(&m_s);
+
(void) fr_sbuff_next(in); /* skip the '(' */
/*
*/
if (xlat_tokenize_argv(node, &node->call.args, in, func,
&xlat_function_arg_rules, t_rules, false) < 0) {
-error:
+ error:
talloc_free(node);
return -1;
}
xlat_flags_merge(&node->flags, &node->call.args->flags);
if (!fr_sbuff_next_if_char(in, ')')) {
- fr_strerror_const("Missing closing brace");
+ fr_strerror_const("Missing closing brace ')'");
goto error;
}
}
if (!fr_sbuff_extend(in)) {
- fr_strerror_const("Missing closing brace");
+ fr_strerror_const("Missing closing brace '}'");
fr_sbuff_marker_release(&m_s);
return -1;
}
}
if (!fr_sbuff_is_char(in, '}')) {
- fr_strerror_const("Missing closing brace");
+ fr_strerror_const("Missing closing brace '}'");
return -1;
}
* e.g. '%{myfirstxlat'
*/
if (!fr_sbuff_extend(in)) {
- fr_strerror_const("Missing closing brace");
+ fr_strerror_const("Missing closing brace '}'");
fr_sbuff_marker_release(&m_s);
return -1;
}
if (xlat_tokenize_attribute(head, in, &attr_p_rules, t_rules) < 0) return -1;
if (!fr_sbuff_next_if_char(in, '}')) {
- fr_strerror_const("Missing closing brace");
+ fr_strerror_const("Missing closing brace '}'");
return -1;
}
switch (quote) {
case T_SOLIDUS_QUOTED_STRING:
fr_strerror_const("Unexpected regular expression");
+ fr_sbuff_advance(in, -1); /* to the actual '/' */
+ our_in = FR_SBUFF(in);
FR_SBUFF_ERROR_RETURN(&our_in);
default:
FR_SBUFF_ERROR_RETURN(&our_in);
case T_BARE_WORD:
+#if 0
+ /*
+ * Avoid a bounce through tmpls for %{...} and %func()
+ */
+ if (fr_sbuff_is_char(&our_in, '%')) {
+ xlat_exp_head_t *head = NULL;
+
+ MEM(head = xlat_exp_head_alloc(ctx));
+
+ slen = xlat_tokenize_input(head, &our_in, p_rules, t_rules);
+ if (slen <= 0) {
+ talloc_free(head);
+ FR_SBUFF_ERROR_RETURN(&our_in);
+ }
+
+ fr_assert(fr_dlist_num_elements(&head->dlist) == 1);
+
+ node = fr_dlist_pop_head(&head->dlist);
+ fr_assert(node != NULL);
+ (void) talloc_steal(ctx, node);
+ talloc_free(head);
+ goto done;
+ }
+#endif
break;
case T_DOUBLE_QUOTED_STRING:
*/
slen = tmpl_afrom_substr(node, &node->vpt, &our_in, quote, p_rules, t_rules);
if (slen <= 0) {
- fr_sbuff_advance(&our_in, -slen); /* point to the correct offset */
+ fr_sbuff_advance(&our_in, -slen - 1); /* point to the correct offset */
error:
talloc_free(node);
/*
* skip spaces at the beginning as we don't want them to become a whitespace literal.
*/
- fr_sbuff_adv_past_whitespace(in, SIZE_MAX, NULL);
+ fr_sbuff_adv_past_whitespace(&our_in, SIZE_MAX, NULL);
fr_sbuff_marker(&m, &our_in);
argc = 1;
fr_token_t quote;
size_t len;
- fr_sbuff_set(&m, &our_in); /* Record start of argument */
arg_t_rules.literals_safe_for = arg->safe_for;
/*
*/
if (!spaces) fr_sbuff_adv_past_whitespace(&our_in, SIZE_MAX, NULL);
+ fr_sbuff_set(&m, &our_in); /* Record start of argument */
+
if (!spaces && !xlat_func_bare_words) {
quote = T_BARE_WORD;
} else {
if (arg->type == FR_TYPE_NULL) {
fr_strerror_printf("Too many arguments, expected %zu, got %d",
(size_t) (arg - arg_start), argc);
+ fr_sbuff_set(&our_in, &m);
goto error;
}
fr_sbuff_t our_in = FR_SBUFF(in);
xlat_exp_head_t *head;
-
MEM(head = xlat_exp_head_alloc(ctx));
fr_strerror_clear(); /* Clear error buffer */
#match ERROR offset 3: Unresolved attributes not allowed in expansions here
xlat %{3
-match ERROR offset 3: Missing closing brace
+match ERROR offset 3: Missing closing brace '}'
#
# Tests for xlat expansion
match %{Tunnel-Password}
xlat %test_no_args('foo')
-match ERROR offset 19: Too many arguments, expected 0, got 1
+match ERROR offset 14: Too many arguments, expected 0, got 1
xlat %test('bar')
match %test('bar')
+xlat %test()
+match ERROR offset 6: Missing required arg 1
+
xlat %{Tunnel-Password}
match %{Tunnel-Password}
match %length()
xlat %length(
-match ERROR offset 8: Missing closing brace
+match ERROR offset 8: Missing closing brace ')'
xlat %length(1 + 2
match ERROR offset 13: Missing ')' after argument 1
# Empty and malformed expansions
#
xlat %{
-match ERROR offset 2: Missing closing brace
+match ERROR offset 2: Missing closing brace '}'
xlat %{}
match ERROR offset 2: Empty expressions are invalid
match ERROR offset 2: Attribute 'foo' not found. Searched in: RADIUS, internal: Unresolved attributes are not allowed here
xlat %test(
-match ERROR offset 6: Missing closing brace
+match ERROR offset 6: Missing closing brace ')'
xlat %test(%{User-Name)
-match ERROR offset 17: Missing closing brace
+match ERROR offset 17: Missing closing brace '}'
-# Discuss - Not sure the offset/message is correct here, but not sure if we can determine the correct offset either
xlat %test(%{User-Name}
match ERROR offset 18: Missing ')' after argument 1
xlat %{myfirstxlat
-match ERROR offset 13: Missing closing brace
+match ERROR offset 13: Missing closing brace '}'
# Issue seen in the wild that caused an SEGV during pass2
xlat %{%{control.IP-Pool.Name}:%{reply.IP-Pool.Range}
-match ERROR offset 48: Missing closing brace
+match ERROR offset 48: Missing closing brace '}'
#
# API to split xlat strings into argv-style arguments.
# to xlat_tokenize_expansion()
#
xlat_argv /bin/sh "foo bar" "%{User-Name} %{Filter-Id"
-match ERROR offset 45: Unexpected text after attribute reference
+match ERROR offset 44: Unexpected text after attribute reference
# and text immediately after a variable expansion
xlat_argv echo hello %{Filter-Id}:1234 world
# so the "offset" is wrong. It also doesn't say *which* string is wrong. We'll fix that later.
#
xlat %rpad(User-Name, 'foo', 'x')
-match ERROR offset 16: Invalid argument 2 - Failed parsing string as type 'uint64'
+match ERROR offset 17: Invalid argument 2 - Failed parsing string as type 'uint64'
#
# Argument quoting
match %md5(0x61726722)
count
-match 157
+match 159