Skip to content

Commit

Permalink
Fix ->toUrl() method for invalid uuids #5367
Browse files Browse the repository at this point in the history
  • Loading branch information
afbora committed Jul 13, 2023
1 parent 32e2a9d commit aff2abc
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 1 deletion.
2 changes: 1 addition & 1 deletion config/components.php
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@
Uuid::is($path, 'file') === true
)
) {
$path = Uuid::for($path)->model()->url();
$path = Uuid::for($path)->model()?->url();
}

$url = Url::makeAbsolute($path, $kirby->url());
Expand Down
47 changes: 47 additions & 0 deletions tests/Cms/Fields/FieldMethodsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,53 @@ public function testToUrlEmpty()
$this->assertNull($field->toUrl());
}

public function testToUuidUrl()
{
$app = new App([
'roots' => [
'index' => $this->tmp
],
'site' => [
'children' => [
[
'slug' => 'test',
'content' => [
'title' => 'Test Title',
'uuid' => 'my-page-uuid'
],
'files' => [
[
'filename' => 'test.jpg',
'content' => [
'uuid' => 'my-file-uuid',
]
]
]
]
]
]
]);

$page = $app->page('page://my-page-uuid');
$field = $this->field('page://my-page-uuid');
$this->assertSame('/test', $field->toUrl());
$this->assertSame($page->url(), $field->toUrl());

$file = $app->file('file://my-file-uuid');
$field = $this->field('file://my-file-uuid');
$this->assertSame('/media/pages/test/' . $file->mediaHash() . '/test.jpg', $field->toUrl());
$this->assertSame($file->url(), $field->toUrl());
}

public function testToInvalidUuidUrl()
{
$field = $this->field('page://invalid');
$this->assertSame('/', $field->toUrl());

$field = $this->field('file://invalid');
$this->assertSame('/', $field->toUrl());
}

public function testToUser()
{
$app = new App([
Expand Down
35 changes: 35 additions & 0 deletions tests/Form/Fields/LinkFieldTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Form\Fields;

use Kirby\Cms\App;
use Kirby\Filesystem\Dir;
use Kirby\Form\Fields\TestCase;

class LinkFieldTest extends TestCase
{
public function testDefaultProps()
{
$field = $this->field('link');

$this->assertSame('link', $field->type());
$this->assertSame('link', $field->name());
$this->assertSame('', $field->value());
$this->assertNull($field->label());
$this->assertNull($field->text());
$this->assertTrue($field->save());
$this->assertNull($field->after());
$this->assertNull($field->before());
$this->assertNull($field->icon());
$this->assertNull($field->placeholder());
$this->assertSame([
'url',
'page',
'file',
'email',
'tel',
'anchor',
'custom'
], $field->options());
}
}

0 comments on commit aff2abc

Please sign in to comment.