Skip to content

Commit 903e7b9

Browse files
Make sure identifiers consisting of only digits are escaped
1 parent 925eb95 commit 903e7b9

File tree

6 files changed

+29
-20
lines changed

6 files changed

+29
-20
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "wikibase-solutions/php-cypher-dsl",
33
"description": "A PHP DSL for the Cypher Query Language",
4-
"version": "2.2.2",
4+
"version": "2.2.3",
55
"type": "library",
66
"keywords": [
77
"neo4j",

src/Traits/EscapeTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public static function escape(string $name): string
4242
return "";
4343
}
4444

45-
if (ctype_alnum($name)) {
45+
if (ctype_alnum($name) && !ctype_digit($name)) {
4646
return $name;
4747
}
4848

tests/Unit/Patterns/RelationshipTest.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,9 @@ public function provideWithPropertiesData(): array
217217
{
218218
return [
219219
[[], Path::DIR_LEFT, "(a)<-[{}]-(b)"],
220-
[[new StringLiteral('a')], Path::DIR_LEFT, "(a)<-[{0: 'a'}]-(b)"],
220+
[[new StringLiteral('a')], Path::DIR_LEFT, "(a)<-[{`0`: 'a'}]-(b)"],
221221
[['a' => new StringLiteral('b')], Path::DIR_LEFT, "(a)<-[{a: 'b'}]-(b)"],
222-
[['a' => new StringLiteral('b'), new StringLiteral('c')], Path::DIR_LEFT, "(a)<-[{a: 'b', 0: 'c'}]-(b)"],
222+
[['a' => new StringLiteral('b'), new StringLiteral('c')], Path::DIR_LEFT, "(a)<-[{a: 'b', `0`: 'c'}]-(b)"],
223223
[[':' => new Decimal(12)], Path::DIR_LEFT, "(a)<-[{`:`: 12}]-(b)"]
224224
];
225225
}
@@ -240,43 +240,43 @@ public function provideWithNameAndPropertiesData(): array
240240
{
241241
return [
242242
['a', [], Path::DIR_LEFT, "(a)<-[a {}]-(b)"],
243-
['b', [new StringLiteral('a')], Path::DIR_LEFT, "(a)<-[b {0: 'a'}]-(b)"],
243+
['b', [new StringLiteral('a')], Path::DIR_LEFT, "(a)<-[b {`0`: 'a'}]-(b)"],
244244
['', ['a' => new StringLiteral('b')], Path::DIR_LEFT, "(a)<-[{a: 'b'}]-(b)"],
245-
[':', ['a' => new StringLiteral('b'), new StringLiteral('c')], Path::DIR_LEFT, "(a)<-[`:` {a: 'b', 0: 'c'}]-(b)"]
245+
[':', ['a' => new StringLiteral('b'), new StringLiteral('c')], Path::DIR_LEFT, "(a)<-[`:` {a: 'b', `0`: 'c'}]-(b)"]
246246
];
247247
}
248248

249249
public function provideWithTypeAndPropertiesData(): array
250250
{
251251
return [
252252
['a', [], Path::DIR_LEFT, "(a)<-[:a {}]-(b)"],
253-
['b', [new StringLiteral('a')], Path::DIR_LEFT, "(a)<-[:b {0: 'a'}]-(b)"],
253+
['b', [new StringLiteral('a')], Path::DIR_LEFT, "(a)<-[:b {`0`: 'a'}]-(b)"],
254254
['', ['a' => new StringLiteral('b')], Path::DIR_LEFT, "(a)<-[{a: 'b'}]-(b)"],
255-
[':', ['a' => new StringLiteral('b'), new StringLiteral('c')], Path::DIR_LEFT, "(a)<-[:`:` {a: 'b', 0: 'c'}]-(b)"]
255+
[':', ['a' => new StringLiteral('b'), new StringLiteral('c')], Path::DIR_LEFT, "(a)<-[:`:` {a: 'b', `0`: 'c'}]-(b)"]
256256
];
257257
}
258258

259259
public function provideWithNameAndTypeAndPropertiesData(): array
260260
{
261261
return [
262262
['a', 'a', [], Path::DIR_LEFT, "(a)<-[a:a {}]-(b)"],
263-
['b', 'a', [new StringLiteral('a')], Path::DIR_LEFT, "(a)<-[b:a {0: 'a'}]-(b)"],
263+
['b', 'a', [new StringLiteral('a')], Path::DIR_LEFT, "(a)<-[b:a {`0`: 'a'}]-(b)"],
264264
['', 'a', ['a' => new StringLiteral('b')], Path::DIR_LEFT, "(a)<-[:a {a: 'b'}]-(b)"],
265-
[':', 'a', ['a' => new StringLiteral('b'), new StringLiteral('c')], Path::DIR_LEFT, "(a)<-[`:`:a {a: 'b', 0: 'c'}]-(b)"],
266-
['a', 'b', [new StringLiteral('a')], Path::DIR_LEFT, "(a)<-[a:b {0: 'a'}]-(b)"],
265+
[':', 'a', ['a' => new StringLiteral('b'), new StringLiteral('c')], Path::DIR_LEFT, "(a)<-[`:`:a {a: 'b', `0`: 'c'}]-(b)"],
266+
['a', 'b', [new StringLiteral('a')], Path::DIR_LEFT, "(a)<-[a:b {`0`: 'a'}]-(b)"],
267267
['a', '', ['a' => new StringLiteral('b')], Path::DIR_LEFT, "(a)<-[a {a: 'b'}]-(b)"],
268-
['a', ':', ['a' => new StringLiteral('b'), new StringLiteral('c')], Path::DIR_LEFT, "(a)<-[a:`:` {a: 'b', 0: 'c'}]-(b)"]
268+
['a', ':', ['a' => new StringLiteral('b'), new StringLiteral('c')], Path::DIR_LEFT, "(a)<-[a:`:` {a: 'b', `0`: 'c'}]-(b)"]
269269
];
270270
}
271271

272272
public function provideWithMultipleTypesData(): array
273273
{
274274
return [
275275
['a', [], [], Path::DIR_LEFT, "(a)<-[a {}]-(b)"],
276-
['b', ['a'], [new StringLiteral('a')], Path::DIR_LEFT, "(a)<-[b:a {0: 'a'}]-(b)"],
276+
['b', ['a'], [new StringLiteral('a')], Path::DIR_LEFT, "(a)<-[b:a {`0`: 'a'}]-(b)"],
277277
['', ['a', 'b'], ['a' => new StringLiteral('b')], Path::DIR_LEFT, "(a)<-[:a|b {a: 'b'}]-(b)"],
278-
[':', ['a', ':'], ['a' => new StringLiteral('b'), new StringLiteral('c')], Path::DIR_LEFT, "(a)<-[`:`:a|`:` {a: 'b', 0: 'c'}]-(b)"],
279-
['a', ['a', 'b', 'c'], [new StringLiteral('a')], Path::DIR_LEFT, "(a)<-[a:a|b|c {0: 'a'}]-(b)"],
278+
[':', ['a', ':'], ['a' => new StringLiteral('b'), new StringLiteral('c')], Path::DIR_LEFT, "(a)<-[`:`:a|`:` {a: 'b', `0`: 'c'}]-(b)"],
279+
['a', ['a', 'b', 'c'], [new StringLiteral('a')], Path::DIR_LEFT, "(a)<-[a:a|b|c {`0`: 'a'}]-(b)"],
280280
['a', ['a', 'b'], [], Path::DIR_LEFT, "(a)<-[a:a|b {}]-(b)"]
281281
];
282282
}

tests/Unit/PropertyMapTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ public function testAddProperty()
103103
public function provideNumericalKeysData(): array
104104
{
105105
return [
106-
[[$this->getQueryConvertableMock(AnyType::class, "'a'")], "{0: 'a'}"],
107-
[[$this->getQueryConvertableMock(AnyType::class, "'a'"), $this->getQueryConvertableMock(AnyType::class, "'b'")], "{0: 'a', 1: 'b'}"]
106+
[[$this->getQueryConvertableMock(AnyType::class, "'a'")], "{`0`: 'a'}"],
107+
[[$this->getQueryConvertableMock(AnyType::class, "'a'"), $this->getQueryConvertableMock(AnyType::class, "'b'")], "{`0`: 'a', `1`: 'b'}"]
108108
];
109109
}
110110

tests/Unit/Traits/EscapeTraitTest.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,11 @@ public function provideSafeValueIsNotEscapedData(): array
105105
['xxx'],
106106
['yyy'],
107107
['zzz'],
108-
['']
108+
[''],
109+
['aaa100'],
110+
['a0'],
111+
['z10'],
112+
['z99']
109113
];
110114
}
111115

@@ -117,7 +121,12 @@ public function provideUnsafeValueIsEscapedData(): array
117121
['_'],
118122
['__'],
119123
['\''],
120-
['"']
124+
['"'],
125+
['0'],
126+
['10'],
127+
['100'],
128+
['1'],
129+
['2']
121130
];
122131
}
123132
}

tests/Unit/VariableTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function provideToQueryData(): array
6262
["a", "a"],
6363
["b", "b"],
6464
[":", "`:`"],
65-
["0", "0"]
65+
["0", "`0`"]
6666
];
6767
}
6868

0 commit comments

Comments
 (0)