Skip to content

Commit

Permalink
Labels with spaces or special characters should be escaped with backt…
Browse files Browse the repository at this point in the history
…icks
  • Loading branch information
wgorder committed Aug 1, 2014
1 parent 2f82ca9 commit ca45149
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 6 deletions.
12 changes: 11 additions & 1 deletion src/main/java/org/neo4j/cypherdsl/CypherQuery.java
Expand Up @@ -192,7 +192,17 @@ public static Parameter param( String name )
*/
public static LabelValue label( String label )
{
checkNull( label, "Label" );
return new LabelValue( identifier( label ) );
}

/**
* Declare a label.
*
* @param label literal value
* @return Label instance
*/
public static LabelValue label( Identifier label )
{
return new LabelValue( label );
}

Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/neo4j/cypherdsl/Path.java
Expand Up @@ -70,6 +70,11 @@ public Path labels( Iterable<LabelValue> labels )
}

public Path label( String label )
{
return new Path( node, relationship, nodePropertyValues, new LabelValue( identifier(label) ) );
}

public Path label( Identifier label )
{
return new Path( node, relationship, nodePropertyValues, new LabelValue( label ) );
}
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/org/neo4j/cypherdsl/query/LabelValue.java
Expand Up @@ -19,21 +19,23 @@
*/
package org.neo4j.cypherdsl.query;

import org.neo4j.cypherdsl.Identifier;

/**
* Represents matching a label to a value
*/
public class LabelValue extends AbstractExpression {

private final String label;
private final Identifier label;

public LabelValue(String label) {
public LabelValue( Identifier label ) {
this.label = label;
}

@Override
public void asString(StringBuilder builder) {
builder.append(":");
builder.append(label);
public void asString( StringBuilder builder ) {
builder.append( ":" );
label.asString( builder );
}

}
22 changes: 22 additions & 0 deletions src/test/java/org/neo4j/cypherdsl/CypherQueryTest2.java
Expand Up @@ -21,6 +21,10 @@

import org.junit.Test;

import static org.neo4j.cypherdsl.CypherQuery.identifier;
import static org.neo4j.cypherdsl.CypherQuery.match;
import static org.neo4j.cypherdsl.CypherQuery.node;

/**
* Tests for all parts of the Cypher DSL.
*/
Expand Down Expand Up @@ -79,4 +83,22 @@ public void testLabel()
}}.toString() );
}

@Test
public void testLabelWithSpaces()
{
assertQueryEquals( CYPHER + "MATCH (movie:`Movie With Spaces`) RETURN movie",
match( node( "movie" ).label( "Movie With Spaces" ) ).
returns( identifier( "movie" ) ).
toString() );
}

@Test
public void testLabelWithSpecialCharacters()
{
assertQueryEquals( CYPHER + "MATCH (movie:`Movie\"#'?!`) RETURN movie",
match( node( "movie" ).label( "Movie\"#'?!" ) ).
returns( identifier( "movie" ) ).
toString() );
}

}

0 comments on commit ca45149

Please sign in to comment.