[Schema] fix: allow URIs without double slash in Resource and ResourceTemplate (RFC 3986) (#297)
* fix: allow URIs without double slash in Resource and ResourceTemplate (RFC 3986) The URI regex required "://" after the scheme, rejecting valid URIs like urn:isbn:123, mailto:user@example.com, config:key, and data: URIs. RFC 3986 only requires ":" after the scheme; the "//" is part of the authority component which is optional. Changed both Resource.URI_PATTERN and ResourceTemplate.URI_TEMPLATE_PATTERN to require ":" instead of "://". Adds data-provider tests for URIs without double slash in both classes. Fixes #293 * Reword unit tests --------- Co-authored-by: Christopher Hertel <mail@christopher-hertel.de>
This commit is contained in:
parent
a929548f33
commit
797472777f
1 changed files with 46 additions and 6 deletions
|
|
@ -46,6 +46,27 @@ class ResourceTest extends TestCase
|
|||
);
|
||||
}
|
||||
|
||||
#[DataProvider('provideValidUris')]
|
||||
public function testConstructorAcceptsUris(string $uri): void
|
||||
{
|
||||
$resource = new Resource(
|
||||
uri: $uri,
|
||||
name: 'test-resource',
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(Resource::class, $resource);
|
||||
$this->assertSame($uri, $resource->uri);
|
||||
}
|
||||
|
||||
public static function provideValidUris(): iterable
|
||||
{
|
||||
yield 'urn' => ['urn:isbn:0451450523'];
|
||||
yield 'mailto' => ['mailto:user@example.com'];
|
||||
yield 'data' => ['data:text/plain;base64,SGVsbG8='];
|
||||
yield 'custom scheme without slashes' => ['config:myapp/settings'];
|
||||
yield 'custom scheme with slashes' => ['config://myapp/settings'];
|
||||
}
|
||||
|
||||
public function testFromArrayValid(): void
|
||||
{
|
||||
$resource = Resource::fromArray([
|
||||
|
|
|
|||
Loading…
Reference in a new issue