Skip to content

Commit

Permalink
Fix recursive descent syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
arr2036 committed Aug 5, 2015
1 parent 83e5b7b commit fd3d4c6
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 19 deletions.
34 changes: 26 additions & 8 deletions src/modules/rlm_json/jpath.c
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,16 @@ char *fr_jpath_aprints(TALLOC_CTX *ctx, fr_jpath_node_t const *head)
break;

case JPATH_SELECTOR_RECURSIVE_DESCENT:
p = talloc_strdup_append_buffer(p, "..");
if (node->next) switch (node->next->selector->type) {
case JPATH_SELECTOR_SLICE:
case JPATH_SELECTOR_INDEX:
p = talloc_strdup_append_buffer(p, "..");
break;

default:
p = talloc_strdup_append_buffer(p, ".");
break;
}
break;

case JPATH_SELECTOR_INVALID:
Expand Down Expand Up @@ -819,14 +828,23 @@ do { \
p++;
goto error;
}
#if 0
node->selector->type = JPATH_SELECTOR_RECURSIVE_DESCENT;
p++;
continue;
#else
fr_strerror_printf("Recursive descent not yet implemented");
goto error;
#endif

if ((p + 1) == end) {
fr_strerror_printf("Path may not end in recursive descent");
goto error;
}

/*
* If and only if, the next char is the beginning
* of a selector, advance the pointer.
*
* Otherwise we leave it pointing to the second '.'
* allowing .* and .<field>
*/
if (p[1] == '[') p++;
continue;

case '*':
node->selector->type = JPATH_SELECTOR_WILDCARD;
p++;
Expand Down
44 changes: 33 additions & 11 deletions src/tests/modules/json/parser.unlang
Original file line number Diff line number Diff line change
Expand Up @@ -219,44 +219,66 @@ if ("%{jpathvalidate:$.foo.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
test_fail
}

# 31. Empty field
# 31. Expect failure - Empty field
if ("%{jpathvalidate:$.foo.[]}" == '6:Empty field specifier') {
test_pass
} else {
test_fail
}

# 32. Expect failure - Filter expressions NYI
if ("%{jpathvalidate:$.foo[?@.bar = baz]}" == '6:Filter expressions not yet implemented') {
# 32. Expect success - Nested array
if ("%{jpathvalidate:$[0][1]}" == '7:$[0][1]') {
test_pass
} else {
test_fail
}

# 33. Expect failure - Expressions NYI
if ("%{jpathvalidate:$.foo[(@.bar = baz)]}" == '6:Expressions not yet implemented') {
# 33. Expect success - Nested array with multiple indicies
if ("%{jpathvalidate:$[0][1,2]}" == '9:$[0][1,2]') {
test_pass
} else {
test_fail
}

# 34. Expect failure - Recursive descent NYI
if ("%{jpathvalidate:$..}" == '2:Recursive descent not yet implemented') {
# 34. Expect failure - Recursive descent followed by nothing
if ("%{jpathvalidate:$..}" == '2:Path may not end in recursive descent') {
test_pass
} else {
test_fail
}

# 35. Nested array
if ("%{jpathvalidate:$[0][1]}" == '7:$[0][1]') {
# 35. Expect success - Recursive descent followed by field
if ("%{jpathvalidate:$..foo}" == '6:$..foo') {
test_pass
} else {
test_fail
}

# 36. Nested array with multiple indicies
if ("%{jpathvalidate:$[0][1,2]}" == '9:$[0][1,2]') {
# 36. Expect success - Recursive descent followed by selector
if ("%{jpathvalidate:$..[0]}" == '6:$..[0]') {
test_pass
} else {
test_fail
}

# 37. Expect success - Recursive descent followed by wildcard
if ("%{jpathvalidate:$..*}" == '4:$..*') {
test_pass
} else {
test_fail
}

# 38. Expect failure - Filter expressions NYI
if ("%{jpathvalidate:$.foo[?@.bar = baz]}" == '6:Filter expressions not yet implemented') {
test_pass
} else {
test_fail
}

# 39. Expect failure - Expressions NYI
if ("%{jpathvalidate:$.foo[(@.bar = baz)]}" == '6:Expressions not yet implemented') {
test_pass
} else {
test_fail
}

0 comments on commit fd3d4c6

Please sign in to comment.