Skip to content

Commit d604329

Browse files
committed
[dsn] add more octal tests
1 parent c44b7c0 commit d604329

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

pkg/dsn/Dsn.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public function getOctal(string $name, int $default = null): ?int
172172
return $default;
173173
}
174174

175-
if (false == preg_match('/^[\+\-]?[0-9]*$/', $value)) {
175+
if (false == preg_match('/^0[\+\-]?[0-7]*$/', $value)) {
176176
throw InvalidQueryParameterTypeException::create($name, 'integer');
177177
}
178178

pkg/dsn/Tests/DsnTest.php

+27
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,33 @@ public function testThrowIfQueryParameterNotInt()
134134
$dsn->getInt('aName');
135135
}
136136

137+
public function testThrowIfQueryParameterNotOctalButString()
138+
{
139+
$dsn = new Dsn('foo:?aName=notInt');
140+
141+
$this->expectException(InvalidQueryParameterTypeException::class);
142+
$this->expectExceptionMessage('The query parameter "aName" has invalid type. It must be "integer"');
143+
$dsn->getOctal('aName');
144+
}
145+
146+
public function testThrowIfQueryParameterNotOctalButDecimal()
147+
{
148+
$dsn = new Dsn('foo:?aName=123');
149+
150+
$this->expectException(InvalidQueryParameterTypeException::class);
151+
$this->expectExceptionMessage('The query parameter "aName" has invalid type. It must be "integer"');
152+
$dsn->getOctal('aName');
153+
}
154+
155+
public function testThrowIfQueryParameterInvalidOctal()
156+
{
157+
$dsn = new Dsn('foo:?aName=0128');
158+
159+
$this->expectException(InvalidQueryParameterTypeException::class);
160+
$this->expectExceptionMessage('The query parameter "aName" has invalid type. It must be "integer"');
161+
$dsn->getOctal('aName');
162+
}
163+
137164
/**
138165
* @dataProvider provideFloatQueryParameters
139166
*/

0 commit comments

Comments
 (0)