Skip to content

Commit

Permalink
Merge pull request #3178 from getkirby/patch/3.5.3.1
Browse files Browse the repository at this point in the history
3.5.3.1
  • Loading branch information
bastianallgeier authored Feb 24, 2021
2 parents 317f494 + 0f3cd9e commit 38afb2d
Show file tree
Hide file tree
Showing 18 changed files with 227 additions and 89 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ jobs:
runs-on: ubuntu-latest
env:
php: "8.0"
php: "7.4" # TODO: Update to PHP 8.0 when PHPMD supports it (https://github.com/phpmd/phpmd/issues/853)
extensions: mbstring, ctype, curl, gd, apcu, memcached

steps:
Expand Down Expand Up @@ -244,9 +244,10 @@ jobs:
if: always() && steps.finishPrepare.outcome == 'success'
run: composer-normalize --dry-run

- name: Check for unused Composer dependencies
if: always() && steps.finishPrepare.outcome == 'success'
run: composer unused --no-progress
# TODO: Re-enable when the fatal error in CI no longer appears
# - name: Check for unused Composer dependencies
# if: always() && steps.finishPrepare.outcome == 'success'
# run: composer unused --no-progress

- name: Check for duplicated code
if: always() && steps.finishPrepare.outcome == 'success'
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"core"
],
"homepage": "https://getkirby.com",
"version": "3.5.3",
"version": "3.5.3.1",
"license": "proprietary",
"authors": [
{
Expand Down
14 changes: 7 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion config/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ function gist(string $url, string $file = null): string
* @param int $code
* @return void
*/
function go(string $url = null, int $code = 302)
function go(string $url = '/', int $code = 302)
{
die(Response::redirect($url, $code));
}
Expand Down
2 changes: 1 addition & 1 deletion config/sections/files.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
'id' => $file->id(),
'icon' => $file->panelIcon($image),
'image' => $image,
'info' => $file->toString($this->info),
'info' => $file->toString($this->info ?? false),
'link' => $file->panelUrl(true),
'mime' => $file->mime(),
'parent' => $file->parent()->panelPath(),
Expand Down
2 changes: 1 addition & 1 deletion config/sections/pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
'id' => $item->id(),
'dragText' => $item->dragText(),
'text' => $item->toString($this->text),
'info' => $item->toString($this->info),
'info' => $item->toString($this->info ?? false),
'parent' => $item->parentId(),
'icon' => $item->panelIcon($image),
'image' => $image,
Expand Down
2 changes: 1 addition & 1 deletion i18n/translations/da.json
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@
"field.blocks.image.name": "Billede",
"field.blocks.image.placeholder": "Vælg et billede",
"field.blocks.image.ratio": "Størrelsesforhold",
"field.blocks.image.url": "Image URL",
"field.blocks.image.url": "Billede URL",
"field.blocks.list.name": "Liste",
"field.blocks.markdown.name": "Markdown",
"field.blocks.markdown.label": "Tekst",
Expand Down
2 changes: 1 addition & 1 deletion i18n/translations/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@
"field.blocks.image.name": "이미지",
"field.blocks.image.placeholder": "이미지 선택",
"field.blocks.image.ratio": "비율",
"field.blocks.image.url": "Image URL",
"field.blocks.image.url": "이미지 URL",
"field.blocks.list.name": "목록",
"field.blocks.markdown.name": "마크다운",
"field.blocks.markdown.label": "마크다운",
Expand Down
2 changes: 1 addition & 1 deletion i18n/translations/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@
"field.blocks.image.name": "Картинка",
"field.blocks.image.placeholder": "Выберите изображение",
"field.blocks.image.ratio": "Соотношение",
"field.blocks.image.url": "Image URL",
"field.blocks.image.url": "URL изображения",
"field.blocks.list.name": "Список",
"field.blocks.markdown.name": "Markdown",
"field.blocks.markdown.label": "Текст",
Expand Down
2 changes: 1 addition & 1 deletion panel/dist/js/app.js

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions panel/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,14 @@ export default {
fatal(html) {
if (html !== null) {
this.$nextTick(() => {
let doc = this.$refs.fatal.contentWindow.document;
doc.open();
doc.write(html);
doc.close();
try {
let doc = this.$refs.fatal.contentWindow.document;
doc.open();
doc.write(html);
doc.close();
} catch (e) {
console.error(e);
}
})
}
}
Expand Down
3 changes: 0 additions & 3 deletions panel/src/components/Forms/Input/ListInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ export default {
return;
}
// removes <p> tags from value
html = html.replace(/(<p>|<\/p>)/gi, "");
this.$emit("input", html);
}
}
Expand Down
37 changes: 36 additions & 1 deletion src/Cache/FileCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Kirby\Toolkit\Dir;
use Kirby\Toolkit\F;
use Kirby\Toolkit\Str;

/**
* File System Cache Driver
Expand Down Expand Up @@ -68,7 +69,41 @@ public function root(): string
*/
protected function file(string $key): string
{
$file = $this->root . '/' . basename($key);
// strip out invalid characters in each path segment
// split by slash or backslash
$keyParts = [];
foreach (preg_split('#([\/\\\\])#', $key, 0, PREG_SPLIT_DELIM_CAPTURE) as $part) {
switch ($part) {
// forward slashes don't need special treatment
case '/':
break;

// backslashes get their own marker in the path
// to differentiate the cache key from one with forward slashes
case '\\':
$keyParts[] = '_backslash';
break;

// empty part means two slashes in a row;
// special marker like for backslashes
case '':
$keyParts[] = '_empty';
break;

// an actual path segment
default:
// check if the segment only contains safe characters;
// underscores are *not* safe to guarantee uniqueness
// as they are used in the special cases
if (preg_match('/^[a-zA-Z0-9-]+$/', $part) === 1) {
$keyParts[] = $part;
} else {
$keyParts[] = Str::slug($part) . '_' . sha1($part);
}
}
}

$file = $this->root . '/' . implode('/', $keyParts);

if (isset($this->options['extension'])) {
return $file . '.' . $this->options['extension'];
Expand Down
111 changes: 106 additions & 5 deletions tests/Cache/FileCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,27 +82,104 @@ public function testFile()
$cache = new FileCache([
'root' => $root = __DIR__ . '/fixtures/file',
]);
$this->assertSame($root . '/test', $method->invoke($cache, '/test'));
$this->assertSame($root . '/_empty/test', $method->invoke($cache, '/test'));

$cache = new FileCache([
'root' => $root = __DIR__ . '/fixtures/file',
]);
$this->assertSame($root . '/test', $method->invoke($cache, '../../test'));
$this->assertSame($root . '/test/_empty', $method->invoke($cache, 'test/'));

$cache = new FileCache([
'root' => $root = __DIR__ . '/fixtures/file',
]);
$this->assertSame($root . '/hype-test', $method->invoke($cache, './hype-test'));
$this->assertSame($root . '/test/_backslash/foo/bar', $method->invoke($cache, 'test\\foo/bar'));

$cache = new FileCache([
'root' => $root = __DIR__ . '/fixtures/file',
]);
$this->assertSame($root . '/dash.test', $method->invoke($cache, './dash.test'));
$this->assertSame($root . '/test/_backslash/_empty/foo/_backslash/bar', $method->invoke($cache, 'test\\/foo\\bar'));

$cache = new FileCache([
'root' => $root = __DIR__ . '/fixtures/file',
]);
$this->assertSame($root . '/test', $method->invoke($cache, '../sub/test/'));
$this->assertSame($root . '/_empty/test/_empty', $method->invoke($cache, '/test/'));

$cache = new FileCache([
'root' => $root = __DIR__ . '/fixtures/file',
]);
$this->assertSame(
$root . '/_9d891e731f75deae56884d79e9816736b7488080/_9d891e731f75deae56884d79e9816736b7488080/test',
$method->invoke($cache, '../../test')
);

$cache = new FileCache([
'root' => $root = __DIR__ . '/fixtures/file',
]);
$this->assertSame(
$root . '/_9d891e731f75deae56884d79e9816736b7488080/test-cache_4caff0c1d0c8eb128ed9896b4b0258ef2848816b',
$method->invoke($cache, '../test.cache')
);

$cache = new FileCache([
'root' => $root = __DIR__ . '/fixtures/file',
]);
$this->assertSame($root . '/_3a52ce780950d4d969792a2559cd519d7ee8c727/test-page', $method->invoke($cache, './test-page'));

$cache = new FileCache([
'root' => $root = __DIR__ . '/fixtures/file',
]);
$this->assertSame(
$root . '/_3a52ce780950d4d969792a2559cd519d7ee8c727/test-cache_4caff0c1d0c8eb128ed9896b4b0258ef2848816b',
$method->invoke($cache, './test.cache')
);

$cache = new FileCache([
'root' => $root = __DIR__ . '/fixtures/file',
]);
$this->assertSame(
$root . '/_9d891e731f75deae56884d79e9816736b7488080/pages/test/_empty',
$method->invoke($cache, '../pages/test/')
);

$cache = new FileCache([
'root' => $root = __DIR__ . '/fixtures/file',
]);
$this->assertSame(
$root . '/_9d891e731f75deae56884d79e9816736b7488080/pages/test-cache_4caff0c1d0c8eb128ed9896b4b0258ef2848816b',
$method->invoke($cache, '../pages/test.cache')
);

$cache = new FileCache([
'root' => $root = __DIR__ . '/fixtures/file',
'extension' => 'cache'
]);
$this->assertSame(
$root . '/_9d891e731f75deae56884d79e9816736b7488080/pages/test.cache',
$method->invoke($cache, '../pages/test')
);

$cache = new FileCache([
'root' => $root = __DIR__ . '/fixtures/file',
'prefix' => 'prefix'
]);
$this->assertSame(
$root . '/prefix/_9d891e731f75deae56884d79e9816736b7488080/pages/test',
$method->invoke($cache, '../pages/test')
);

$cache = new FileCache([
'root' => $root = __DIR__ . '/fixtures/file',
'prefix' => 'prefix',
'extension' => 'cache'
]);
$this->assertSame(
$root . '/prefix/_9d891e731f75deae56884d79e9816736b7488080/pages/test.cache',
$method->invoke($cache, '../pages/test')
);
$this->assertSame(
$root . '/prefix/_9d891e731f75deae56884d79e9816736b7488080/pages/test-invalid_76a6bcc476cffdcb56321fbbb4edfd19fece82c6.cache',
$method->invoke($cache, '../pages/test.invalid')
);
}

/**
Expand Down Expand Up @@ -132,6 +209,11 @@ public function testOperations()
$this->assertFalse($cache->exists('foo'));
$this->assertNull($cache->retrieve('foo'));

$this->assertDirectoryDoesNotExist($root . '/bar');
$this->assertTrue($cache->set('bar/baz', 'Another basic value', 10));
$this->assertFileExists($root . '/bar/baz');
$this->assertSame('Another basic value', $cache->retrieve('bar/baz')->value());

$this->assertFalse($cache->remove('doesnotexist'));
}

Expand All @@ -158,6 +240,11 @@ public function testOperationsWithExtension()
$this->assertSame($time, $cache->created('foo'));
$this->assertSame($time + 600, $cache->expires('foo'));

$this->assertDirectoryDoesNotExist($root . '/bar');
$this->assertTrue($cache->set('bar/baz', 'Another basic value', 10));
$this->assertFileExists($root . '/bar/baz.cache');
$this->assertSame('Another basic value', $cache->retrieve('bar/baz')->value());

$this->assertTrue($cache->remove('foo'));
$this->assertFileDoesNotExist($root . '/foo.cache');
$this->assertFalse($cache->exists('foo'));
Expand Down Expand Up @@ -196,6 +283,11 @@ public function testOperationsWithPrefix()
touch($root . '/test2/foo', $time);
$this->assertTrue($cache2->exists('foo'));

$this->assertDirectoryDoesNotExist($root . '/test1/bar');
$this->assertTrue($cache1->set('bar/baz', 'Another basic value', 10));
$this->assertFileExists($root . '/test1/bar/baz');
$this->assertSame('Another basic value', $cache1->retrieve('bar/baz')->value());

$this->assertSame('A basic value', $cache1->retrieve('foo')->value());
$this->assertTrue($cache1->remove('foo'));
$this->assertFileDoesNotExist($root . '/test1/foo');
Expand All @@ -217,14 +309,17 @@ public function testFlush()
$cache->set('a', 'A basic value');
$cache->set('b', 'A basic value');
$cache->set('c', 'A basic value');
$cache->set('d/a', 'A basic value');
$this->assertFileExists($root . '/a');
$this->assertFileExists($root . '/b');
$this->assertFileExists($root . '/c');
$this->assertFileExists($root . '/d/a');

$this->assertTrue($cache->flush());
$this->assertFileDoesNotExist($root . '/a');
$this->assertFileDoesNotExist($root . '/b');
$this->assertFileDoesNotExist($root . '/c');
$this->assertDirectoryDoesNotExist($root . '/d');
}

/**
Expand All @@ -245,15 +340,21 @@ public function testFlushWithPrefix()
$cache1->set('b', 'A basic value');
$cache2->set('a', 'A basic value');
$cache2->set('b', 'A basic value');
$cache1->set('c/a', 'A basic value');
$cache2->set('c/a', 'A basic value');
$this->assertFileExists($root . '/test1/a');
$this->assertFileExists($root . '/test1/b');
$this->assertFileExists($root . '/test2/a');
$this->assertFileExists($root . '/test2/b');
$this->assertFileExists($root . '/test2/c/a');
$this->assertFileExists($root . '/test2/c/a');

$this->assertTrue($cache1->flush());
$this->assertFileDoesNotExist($root . '/test1/a');
$this->assertFileDoesNotExist($root . '/test1/b');
$this->assertDirectoryDoesNotExist($root . '/test1/c');
$this->assertFileExists($root . '/test2/a');
$this->assertFileExists($root . '/test2/b');
$this->assertFileExists($root . '/test2/c/a');
}
}
Loading

0 comments on commit 38afb2d

Please sign in to comment.