apoc icon indicating copy to clipboard operation
apoc copied to clipboard

Expand Path methods don't handle label filters where the label filter contains characters that would normally need to be escaped using backticks

Open neo-technology-build-agent opened this issue 3 years ago • 1 comments

Issue by mdw00d Friday Feb 07, 2020 at 18:37 GMT Originally opened as https://github.com/neo4j-contrib/neo4j-apoc-procedures/issues/1407


Expected Behavior

If one is working with a graph where properties and labels contain characters that might normally need to be escaped, including characters such as the special filter qualifiers, then the library does not function as expected.

For example, suppose a node has both the label http://www.w3.org/2002/07/owl#Class and (for the sake of demonstrating this issue), the label OwlClass.

I would expect that

MATCH (v1:`http://example.com/abc#Object`) where v1.uri = "node1e0g5tmg9x4628" call apoc.path.expand(v1, '>|<', '/OwlClass', 0, 2) yield path return distinct nodes(path)

and

MATCH (v1:`http://example.com/abc#Object`) where v1.uri = "node1e0g5tmg9x4628" call apoc.path.expand(v1, '>|<', '/http://www.w3.org/2002/07/owl#Class', 0, 2) yield path return distinct nodes(path)

to return the same results, but the later returns no response while the former returns content.

Versions

  • OS:
  • Neo4j: 3.5
  • Neo4j-Apoc: 3.5.0.6

Comment by mdw00d Sunday Feb 09, 2020 at 00:50 GMT


This behavior is also observed using APOC 3.5.0.7.

Hi there! This is due to how labels filters are created. In this case, the colon : represents a compound label. So in your second example, the termination node filter is actually looking for the node with 2 labels: /http and `://www.w3.org/2002/07/owl#Class'. This is fixed by adding an escape before the colon:

MATCH (v1:`http://example.com/abc#Object`)
WHERE v1.uri = "node1e0g5tmg9x4628"
CALL apoc.path.expand(v1, '>|<', '/http\://www.w3.org/2002/07/owl#Class', 0, 2)
YIELD path RETURN distinct nodes(path)

I will update the docs to make this clearer :)

gem-neo4j avatar Jan 02 '25 07:01 gem-neo4j