Skip to content

Commit 084d0cd

Browse files
Copilotanderly
andcommitted
Add validation for '@' character in custom option keys per OData specification
Co-authored-by: anderly <573151+anderly@users.noreply.github.com>
1 parent d781d1c commit 084d0cd

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

src/Query/Builder.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ public function whereKey($id)
269269
* Array format: ['key' => 'value', 'key2' => 'value2']
270270
*
271271
* Custom option keys must follow OData naming conventions:
272-
* - Must not start with '$' (reserved for standard OData parameters)
272+
* - Must not start with '$' or '@' (reserved for standard OData parameters)
273273
* - Must be valid identifiers (alphanumeric and underscores)
274274
* - Cannot be empty
275275
*
@@ -370,9 +370,9 @@ protected function validateCustomOptionKey($key)
370370
throw new \InvalidArgumentException('Custom option key must be a non-empty string');
371371
}
372372

373-
// Check if key starts with '$' (reserved for OData system parameters)
374-
if (strpos($key, '$') === 0) {
375-
throw new \InvalidArgumentException("Custom option key '$key' cannot start with '\$' (reserved for OData system parameters)");
373+
// Check if key starts with '$' or '@' (reserved for OData system parameters)
374+
if (strpos($key, '$') === 0 || strpos($key, '@') === 0) {
375+
throw new \InvalidArgumentException("Custom option key '$key' cannot start with '\$' or '@' (reserved for OData system parameters)");
376376
}
377377

378378
// Check for valid identifier pattern (alphanumeric, underscores, hyphens)

tests/Query/CustomOptionsTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,21 @@ public function testAddOptionIgnoresNullAndEmpty()
170170
public function testAddOptionValidatesKeyStartingWithDollar()
171171
{
172172
$this->expectException(\InvalidArgumentException::class);
173-
$this->expectExceptionMessage('Custom option key \'$invalid\' cannot start with \'$\'');
173+
$this->expectExceptionMessage('Custom option key \'$invalid\' cannot start with \'$\' or \'@\'');
174174

175175
$builder = $this->getBuilder();
176176
$builder->addOption(['$invalid' => 'value']);
177177
}
178178

179+
public function testAddOptionValidatesKeyStartingWithAt()
180+
{
181+
$this->expectException(\InvalidArgumentException::class);
182+
$this->expectExceptionMessage('Custom option key \'@invalid\' cannot start with \'$\' or \'@\'');
183+
184+
$builder = $this->getBuilder();
185+
$builder->addOption(['@invalid' => 'value']);
186+
}
187+
179188
public function testAddOptionValidatesEmptyKey()
180189
{
181190
$this->expectException(\InvalidArgumentException::class);

0 commit comments

Comments
 (0)