Skip to content

Commit

Permalink
[api] fix parsing of XPATH searches using not() in the correct way
Browse files Browse the repository at this point in the history
We have to support the old incorrect way nevertheless since too many
tools are using it.
  • Loading branch information
adrianschroeter committed Jun 8, 2016
1 parent 0044726 commit 25fbe32
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/api/lib/xpath_engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -652,13 +652,18 @@ def xpath_func_not(root, expr)
# Note that this can result in bloated SQL statements, so some trust in the query optimization
# capabilities of your DBMS is neeed :-)

@condition_values_needed = 2
cond = evaluate_expr(expr, root)

condition = "(NOT #{cond} OR ISNULL(#{cond}))"
if [:child, :attribute].include? expr.first
# for incorrect writings of not(@name) as existens check
# we used to support it :/
@condition_values_needed = 2 if expr.first == :attribute
cond = evaluate_expr(expr, root)
condition = "(NOT #{cond} OR ISNULL(#{cond}))"
@condition_values_needed = 1
else
parse_predicate(root, expr)
condition = "(#{@conditions.pop})"
end
# logger.debug "-- condition : [#{condition}]"

@condition_values_needed = 1
@conditions << condition
end

Expand Down
11 changes: 11 additions & 0 deletions src/api/test/functional/search_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,17 @@ def test_xpath_8
assert_xml_tag content: "#&lt;NoMethodError: undefined method `[]' for nil:NilClass&gt;"
end

def test_xpath_not_method
login_Iggy
# not correct, but we used to support it :/
get "/search/package", match: '[not(@name)]'
assert_response :success
# this needs to work as well osc#205)
get "/search/package", match: '[not(@name="home:Iggy")]'
assert_response :success
assert_xml_tag tag: 'collection'
end

def test_xpath_search_for_person_or_group
# used by maintenance people
login_Iggy
Expand Down

0 comments on commit 25fbe32

Please sign in to comment.