File tree Expand file tree Collapse file tree 3 files changed +22
-10
lines changed Expand file tree Collapse file tree 3 files changed +22
-10
lines changed Original file line number Diff line number Diff line change @@ -33,18 +33,16 @@ trait EscapeTrait
33
33
{
34
34
/**
35
35
* Escapes a 'name' if it needs to be escaped.
36
+ * @see https://neo4j.com/docs/cypher-manual/4.4/syntax/naming
36
37
* A 'name' in cypher is any string that should be included directly in a cypher query,
37
38
* such as variable names, labels, property names and relation types
38
39
*
39
- * Note that empty strings are usually not allowed as names, so these should not be passed to this function.
40
- * However, some neo4j versions do not crash on empty string as variable name, so let's just escape them anyways.
41
- *
42
40
* @param string $name
43
41
* @return string
44
42
*/
45
43
public static function escape (string $ name ): string
46
44
{
47
- if ($ name !== '' && preg_match ('/^\p{L}[\p{L}\d_]*$/u ' , $ name )) {
45
+ if (preg_match ('/^\p{L}[\p{L}\d_]*$/u ' , $ name )) {
48
46
return $ name ;
49
47
}
50
48
@@ -57,7 +55,6 @@ public static function escape(string $name): string
57
55
*/
58
56
public static function escapeRaw ($ name )
59
57
{
60
-
61
58
// Escape backticks that are included in $name by doubling them.
62
59
$ name = str_replace ('` ' , '`` ' , $ name );
63
60
Original file line number Diff line number Diff line change @@ -48,6 +48,7 @@ public function testEmptyNode(): void
48
48
$ this ->assertSame ($ name , $ node ->getVariable ());
49
49
}
50
50
51
+ // Further tests can be found in Traits/EscapeTraitTest
51
52
public function testBacktickIsEscaped (): void
52
53
{
53
54
$ node = new Node ();
Original file line number Diff line number Diff line change @@ -65,11 +65,6 @@ public function testUnsafeValueIsEscaped(string $value)
65
65
$ this ->assertSame ($ expected , $ actual );
66
66
}
67
67
68
- public function testValueWithBacktickIsProperlyEscaped ()
69
- {
70
- $ this ->assertSame ('`foo``bar` ' , $ this ->trait ->escape ("foo`bar " ));
71
- }
72
-
73
68
public function provideSafeValueIsNotEscapedData (): array
74
69
{
75
70
return [
@@ -104,4 +99,23 @@ public function provideUnsafeValueIsEscapedData(): array
104
99
['2 ' ],
105
100
];
106
101
}
102
+
103
+ /**
104
+ * @dataProvider provideValueWithBacktickIsProperlyEscapedData
105
+ */
106
+ public function testValueWithBacktickIsProperlyEscaped ($ input , $ expected )
107
+ {
108
+ $ this ->assertSame ('`foo``bar` ' , $ this ->trait ->escape ("foo`bar " ));
109
+ }
110
+
111
+ public function provideValueWithBacktickIsProperlyEscapedData (): array
112
+ {
113
+ return [
114
+ ['foo`bar ' ,'`foo``bar` ' ],
115
+ ['`foo ' ,'```foo` ' ],
116
+ ['foo` ' ,'`foo``` ' ],
117
+ ['foo``bar ' ,'`foo````bar` ' ],
118
+ ['`foo` ' ,'```foo``` ' ],
119
+ ];
120
+ }
107
121
}
You can’t perform that action at this time.
0 commit comments