Merge branch 'master' into branch-2.10
This commit is contained in:
commit
e3eeb848b7
4 changed files with 42 additions and 7 deletions
|
@ -5,10 +5,14 @@
|
||||||
* @param T|false $x
|
* @param T|false $x
|
||||||
* @return T
|
* @return T
|
||||||
*/
|
*/
|
||||||
function false_throws(mixed $x): mixed
|
function false_throws(mixed $x, ?callable $errorgen = null): mixed
|
||||||
{
|
{
|
||||||
if($x === false) {
|
if($x === false) {
|
||||||
throw new \Exception("Unexpected false");
|
$msg = "Unexpected false";
|
||||||
|
if($errorgen) {
|
||||||
|
$msg = $errorgen();
|
||||||
|
}
|
||||||
|
throw new \Exception($msg);
|
||||||
}
|
}
|
||||||
return $x;
|
return $x;
|
||||||
}
|
}
|
||||||
|
@ -18,10 +22,14 @@ function false_throws(mixed $x): mixed
|
||||||
* @param T|null $x
|
* @param T|null $x
|
||||||
* @return T
|
* @return T
|
||||||
*/
|
*/
|
||||||
function null_throws(mixed $x): mixed
|
function null_throws(mixed $x, ?callable $errorgen = null): mixed
|
||||||
{
|
{
|
||||||
if($x === null) {
|
if($x === null) {
|
||||||
throw new \Exception("Unexpected null");
|
$msg = "Unexpected null";
|
||||||
|
if($errorgen) {
|
||||||
|
$msg = $errorgen();
|
||||||
|
}
|
||||||
|
throw new \Exception($msg);
|
||||||
}
|
}
|
||||||
return $x;
|
return $x;
|
||||||
}
|
}
|
||||||
|
@ -31,7 +39,7 @@ function null_throws(mixed $x): mixed
|
||||||
*/
|
*/
|
||||||
function json_encode_ex(mixed $value, int|null $flags = 0, int $depth = 512): string
|
function json_encode_ex(mixed $value, int|null $flags = 0, int $depth = 512): string
|
||||||
{
|
{
|
||||||
return false_throws(json_encode($value, $flags, $depth));
|
return false_throws(json_encode($value, $flags, $depth), "json_last_error_msg");
|
||||||
}
|
}
|
||||||
|
|
||||||
function strtotime_ex(string $time, int|null $now = null): int
|
function strtotime_ex(string $time, int|null $now = null): int
|
||||||
|
|
|
@ -31,7 +31,7 @@ _d("DEBUG", false); // boolean print various debugging details
|
||||||
_d("COOKIE_PREFIX", 'shm'); // string if you run multiple galleries with non-shared logins, give them different prefixes
|
_d("COOKIE_PREFIX", 'shm'); // string if you run multiple galleries with non-shared logins, give them different prefixes
|
||||||
_d("SPEED_HAX", false); // boolean do some questionable things in the name of performance
|
_d("SPEED_HAX", false); // boolean do some questionable things in the name of performance
|
||||||
_d("WH_SPLITS", 1); // int how many levels of subfolders to put in the warehouse
|
_d("WH_SPLITS", 1); // int how many levels of subfolders to put in the warehouse
|
||||||
_d("VERSION", "2.10.3"); // string shimmie version
|
_d("VERSION", "2.11.0-alpha"); // string shimmie version
|
||||||
_d("TIMEZONE", null); // string timezone
|
_d("TIMEZONE", null); // string timezone
|
||||||
_d("EXTRA_EXTS", ""); // string optional extra extensions
|
_d("EXTRA_EXTS", ""); // string optional extra extensions
|
||||||
_d("BASE_HREF", null); // string force a specific base URL (default is auto-detect)
|
_d("BASE_HREF", null); // string force a specific base URL (default is auto-detect)
|
||||||
|
|
27
core/tests/StdLibExTest.php
Normal file
27
core/tests/StdLibExTest.php
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Shimmie2;
|
||||||
|
|
||||||
|
class StdLibExTest extends ShimmiePHPUnitTestCase
|
||||||
|
{
|
||||||
|
public function testJsonEncodeOk(): void
|
||||||
|
{
|
||||||
|
$this->assertEquals(
|
||||||
|
'{"a":1,"b":2,"c":3,"d":4,"e":5}',
|
||||||
|
json_encode_ex(['a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testJsonEncodeError(): void
|
||||||
|
{
|
||||||
|
$e = $this->assertException(\Exception::class, function () {
|
||||||
|
json_encode_ex("\xB1\x31");
|
||||||
|
});
|
||||||
|
$this->assertEquals(
|
||||||
|
"Malformed UTF-8 characters, possibly incorrectly encoded",
|
||||||
|
$e->getMessage()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -255,7 +255,7 @@ class CommentListTheme extends Themelet
|
||||||
$h_del = "";
|
$h_del = "";
|
||||||
if ($user->can(Permissions::DELETE_COMMENT)) {
|
if ($user->can(Permissions::DELETE_COMMENT)) {
|
||||||
$comment_preview = substr(html_unescape($tfe->stripped), 0, 50);
|
$comment_preview = substr(html_unescape($tfe->stripped), 0, 50);
|
||||||
$j_delete_confirm_message = json_encode_ex("Delete comment by {$comment->owner_name}:\n$comment_preview");
|
$j_delete_confirm_message = json_encode("Delete comment by {$comment->owner_name}:\n$comment_preview") ?: "Delete <corrupt comment>";
|
||||||
$h_delete_script = html_escape("return confirm($j_delete_confirm_message);");
|
$h_delete_script = html_escape("return confirm($j_delete_confirm_message);");
|
||||||
$h_delete_link = make_link("comment/delete/$i_comment_id/$i_image_id");
|
$h_delete_link = make_link("comment/delete/$i_comment_id/$i_image_id");
|
||||||
$h_del = " - <a onclick='$h_delete_script' href='$h_delete_link'>Del</a>";
|
$h_del = " - <a onclick='$h_delete_script' href='$h_delete_link'>Del</a>";
|
||||||
|
|
Reference in a new issue