From 9cc83dad30244a189c06d453dd88c44500ecc44a Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Sun, 22 Dec 2019 10:46:10 +0800 Subject: [PATCH] Remove restriction of texture name and nickname --- app/Http/Controllers/AdminController.php | 4 +--- app/Http/Controllers/AuthController.php | 2 +- app/Http/Controllers/ClosetController.php | 4 ++-- app/Http/Controllers/SetupController.php | 2 +- app/Http/Controllers/SkinlibController.php | 4 ++-- app/Http/Controllers/UserController.php | 4 +--- app/Providers/ValidatorExtendServiceProvider.php | 10 ---------- resources/lang/en/validation.yml | 1 - resources/misc/changelogs/en/5.0.0.md | 1 + resources/misc/changelogs/zh_CN/5.0.0.md | 1 + .../HttpTest/ControllersTest/AdminControllerTest.php | 6 ------ .../HttpTest/ControllersTest/AuthControllerTest.php | 11 ----------- .../ControllersTest/ClosetControllerTest.php | 10 ---------- .../HttpTest/ControllersTest/SetupControllerTest.php | 12 ------------ .../ControllersTest/SkinlibControllerTest.php | 11 ----------- .../HttpTest/ControllersTest/UserControllerTest.php | 12 ------------ 16 files changed, 10 insertions(+), 85 deletions(-) diff --git a/app/Http/Controllers/AdminController.php b/app/Http/Controllers/AdminController.php index e16da0fb..5b3a4e06 100644 --- a/app/Http/Controllers/AdminController.php +++ b/app/Http/Controllers/AdminController.php @@ -593,9 +593,7 @@ class AdminController extends Controller return json(trans('admin.users.operations.verification.success'), 0); } elseif ($action == 'nickname') { - $this->validate($request, [ - 'nickname' => 'required|no_special_chars', - ]); + $this->validate($request, ['nickname' => 'required']); $user->nickname = $request->input('nickname'); $user->save(); diff --git a/app/Http/Controllers/AuthController.php b/app/Http/Controllers/AuthController.php index 27435b0f..2e09458e 100644 --- a/app/Http/Controllers/AuthController.php +++ b/app/Http/Controllers/AuthController.php @@ -121,7 +121,7 @@ class AuthController extends Controller $rule = option('register_with_player_name') ? ['player_name' => 'required|player_name|min:'.option('player_name_length_min').'|max:'.option('player_name_length_max')] : - ['nickname' => 'required|no_special_chars|max:255']; + ['nickname' => 'required|max:255']; $data = $this->validate($request, array_merge([ 'email' => 'required|email|unique:users', 'password' => 'required|min:8|max:32', diff --git a/app/Http/Controllers/ClosetController.php b/app/Http/Controllers/ClosetController.php index f106dd00..78acc2d3 100644 --- a/app/Http/Controllers/ClosetController.php +++ b/app/Http/Controllers/ClosetController.php @@ -85,7 +85,7 @@ class ClosetController extends Controller { $this->validate($request, [ 'tid' => 'required|integer', - 'name' => 'required|no_special_chars', + 'name' => 'required', ]); $user = Auth::user(); @@ -126,7 +126,7 @@ class ClosetController extends Controller public function rename(Request $request, $tid) { - $this->validate($request, ['name' => 'required|no_special_chars']); + $this->validate($request, ['name' => 'required']); $user = auth()->user(); if ($user->closet()->where('tid', $request->tid)->count() == 0) { diff --git a/app/Http/Controllers/SetupController.php b/app/Http/Controllers/SetupController.php index be87ee71..0e3dddfe 100644 --- a/app/Http/Controllers/SetupController.php +++ b/app/Http/Controllers/SetupController.php @@ -115,7 +115,7 @@ class SetupController extends Controller { $data = $this->validate($request, [ 'email' => 'required|email', - 'nickname' => 'required|no_special_chars|max:255', + 'nickname' => 'required', 'password' => 'required|min:8|max:32|confirmed', 'site_name' => 'required', ]); diff --git a/app/Http/Controllers/SkinlibController.php b/app/Http/Controllers/SkinlibController.php index 9dab05e8..257d1925 100644 --- a/app/Http/Controllers/SkinlibController.php +++ b/app/Http/Controllers/SkinlibController.php @@ -362,7 +362,7 @@ class SkinlibController extends Controller { $this->validate($request, [ 'tid' => 'required|integer', - 'new_name' => 'required|no_special_chars', + 'new_name' => 'required', ]); $user = $request->user(); $t = Texture::find($request->input('tid')); @@ -427,7 +427,7 @@ class SkinlibController extends Controller $this->validate($request, [ 'name' => [ 'required', - option('texture_name_regexp') ? 'regex:'.option('texture_name_regexp') : 'no_special_chars', + option('texture_name_regexp') ? 'regex:'.option('texture_name_regexp') : 'string', ], 'file' => 'required|max:'.option('max_upload_file_size'), 'public' => 'required', diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 41a9ddcf..6169a444 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -251,9 +251,7 @@ class UserController extends Controller return json(trans('user.profile.nickname.single'), 1); } - $this->validate($request, [ - 'new_nickname' => 'required|no_special_chars|max:255', - ]); + $this->validate($request, ['new_nickname' => 'required']); $nickname = $request->input('new_nickname'); $user->nickname = $nickname; diff --git a/app/Providers/ValidatorExtendServiceProvider.php b/app/Providers/ValidatorExtendServiceProvider.php index ae92b6af..cee8525c 100644 --- a/app/Providers/ValidatorExtendServiceProvider.php +++ b/app/Providers/ValidatorExtendServiceProvider.php @@ -14,16 +14,6 @@ class ValidatorExtendServiceProvider extends ServiceProvider */ public function boot() { - /* - * @param $a attribute - * @param $value value - * @param $p parameters - * @param $v validator - */ - Validator::extend('no_special_chars', function ($a, $value, $p, $v) { - return $value === e(addslashes(trim($value))); - }); - Validator::extend('player_name', function ($a, $value, $p, $v) { $regexp = '/^(.*)$/'; diff --git a/resources/lang/en/validation.yml b/resources/lang/en/validation.yml index 10ca3ebe..57391bf5 100644 --- a/resources/lang/en/validation.yml +++ b/resources/lang/en/validation.yml @@ -1,7 +1,6 @@ # Blessing Skin username: ':attribute format is invalid.' player_name: 'The :attribute contains invalid character.' -no_special_chars: 'The :attribute must not contain special characters.' model: 'The :attribute must be steve, alex or cape.' accepted: 'The :attribute must be accepted.' diff --git a/resources/misc/changelogs/en/5.0.0.md b/resources/misc/changelogs/en/5.0.0.md index 301e0d92..995a881f 100644 --- a/resources/misc/changelogs/en/5.0.0.md +++ b/resources/misc/changelogs/en/5.0.0.md @@ -47,6 +47,7 @@ - Removed package `swiggles/memcache`. - Removed `commit` property from `blessing` global. - Removed Element UI. +- Removed restriction of texture name and nickname. ## Internal Changes diff --git a/resources/misc/changelogs/zh_CN/5.0.0.md b/resources/misc/changelogs/zh_CN/5.0.0.md index dbebd2f8..afd9d06d 100644 --- a/resources/misc/changelogs/zh_CN/5.0.0.md +++ b/resources/misc/changelogs/zh_CN/5.0.0.md @@ -47,6 +47,7 @@ - 移除扩展包 `swiggles/memcache` - 从全局变量 `blessing` 中移除 `commit` 属性 - 移除 Element UI +- 移除对材质名和用户昵称的要求 ## 内部更改 diff --git a/tests/HttpTest/ControllersTest/AdminControllerTest.php b/tests/HttpTest/ControllersTest/AdminControllerTest.php index 4c79bf9c..8058aa1a 100644 --- a/tests/HttpTest/ControllersTest/AdminControllerTest.php +++ b/tests/HttpTest/ControllersTest/AdminControllerTest.php @@ -292,12 +292,6 @@ class AdminControllerTest extends TestCase ['uid' => $user->uid, 'action' => 'nickname'] )->assertJsonValidationErrors(['nickname']); - // Action is `nickname` but with an invalid nickname - $this->postJson( - '/admin/users', - ['uid' => $user->uid, 'action' => 'nickname', 'nickname' => '\\'] - )->assertJsonValidationErrors(['nickname']); - // Set nickname successfully $this->postJson( '/admin/users', diff --git a/tests/HttpTest/ControllersTest/AuthControllerTest.php b/tests/HttpTest/ControllersTest/AuthControllerTest.php index 5de29d3b..459669cb 100644 --- a/tests/HttpTest/ControllersTest/AuthControllerTest.php +++ b/tests/HttpTest/ControllersTest/AuthControllerTest.php @@ -282,17 +282,6 @@ class AuthControllerTest extends TestCase ] )->assertJsonValidationErrors('nickname'); - // Should return a warning if `nickname` is invalid - $this->postJson( - '/auth/register', - [ - 'email' => 'a@b.c', - 'password' => '12345678', - 'nickname' => '\\', - 'captcha' => 'a', - ] - )->assertJsonValidationErrors('nickname'); - // Should return a warning if `nickname` is too long $this->postJson( '/auth/register', diff --git a/tests/HttpTest/ControllersTest/ClosetControllerTest.php b/tests/HttpTest/ControllersTest/ClosetControllerTest.php index 790572c0..76e57df4 100644 --- a/tests/HttpTest/ControllersTest/ClosetControllerTest.php +++ b/tests/HttpTest/ControllersTest/ClosetControllerTest.php @@ -106,12 +106,6 @@ class ClosetControllerTest extends TestCase ['tid' => 0] )->assertJsonValidationErrors('name'); - // `name` field has special characters - $this->postJson( - '/user/closet/add', - ['tid' => 0, 'name' => '\\'] - )->assertJsonValidationErrors('name'); - // The user doesn't have enough score to add a texture $this->user->score = 0; $this->user->save(); @@ -181,10 +175,6 @@ class ClosetControllerTest extends TestCase // Missing `name` field $this->postJson('/user/closet/rename/0')->assertJsonValidationErrors('name'); - // `new_name` field has special characters - $this->postJson('/user/closet/rename/0', ['name' => '\\']) - ->assertJsonValidationErrors('name'); - // Rename a not-existed texture $this->postJson('/user/closet/rename/-1', ['name' => $name]) ->assertJson([ diff --git a/tests/HttpTest/ControllersTest/SetupControllerTest.php b/tests/HttpTest/ControllersTest/SetupControllerTest.php index 1f8a3652..49ea3868 100644 --- a/tests/HttpTest/ControllersTest/SetupControllerTest.php +++ b/tests/HttpTest/ControllersTest/SetupControllerTest.php @@ -109,18 +109,6 @@ class SetupControllerTest extends TestCase 'email' => 'a@b.c', ])->assertDontSee(trans('setup.wizard.finish.title')); - // Invalid characters in nickname - $this->post('/setup/finish', [ - 'email' => 'a@b.c', - 'nickname' => '\\', - ])->assertDontSee(trans('setup.wizard.finish.title')); - - // Too long nickname - $this->post('/setup/finish', [ - 'email' => 'a@b.c', - 'nickname' => Str::random(256), - ])->assertDontSee(trans('setup.wizard.finish.title')); - // Without `password` field $this->post('/setup/finish', [ 'email' => 'a@b.c', diff --git a/tests/HttpTest/ControllersTest/SkinlibControllerTest.php b/tests/HttpTest/ControllersTest/SkinlibControllerTest.php index c3770ce4..79ec60ba 100644 --- a/tests/HttpTest/ControllersTest/SkinlibControllerTest.php +++ b/tests/HttpTest/ControllersTest/SkinlibControllerTest.php @@ -397,10 +397,6 @@ class SkinlibControllerTest extends TestCase // Without `name` field $this->postJson('/skinlib/upload')->assertJsonValidationErrors('name'); - // With some special chars - $this->postJson('/skinlib/upload', ['name' => '\\']) - ->assertJsonValidationErrors('name'); - // Specified regular expression for texture name option(['texture_name_regexp' => '/\\d+/']); $this->postJson('/skinlib/upload', [ @@ -846,13 +842,6 @@ class SkinlibControllerTest extends TestCase ]) ->assertJsonValidationErrors('new_name'); - // `new_name` has special chars - $this->postJson('/skinlib/rename', [ - 'tid' => $texture->tid, - 'new_name' => '\\', - ]) - ->assertJsonValidationErrors('new_name'); - // Non-existed texture $this->postJson('/skinlib/rename', [ 'tid' => -1, diff --git a/tests/HttpTest/ControllersTest/UserControllerTest.php b/tests/HttpTest/ControllersTest/UserControllerTest.php index 26ec9202..224a1dc1 100644 --- a/tests/HttpTest/ControllersTest/UserControllerTest.php +++ b/tests/HttpTest/ControllersTest/UserControllerTest.php @@ -268,18 +268,6 @@ class UserControllerTest extends TestCase $this->postJson('/user/profile', ['action' => 'nickname']) ->assertJsonValidationErrors('new_nickname'); - // Invalid nickname - $this->postJson('/user/profile', [ - 'action' => 'nickname', - 'new_nickname' => '\\', - ])->assertJsonValidationErrors('new_nickname'); - - // Too long nickname - $this->postJson('/user/profile', [ - 'action' => 'nickname', - 'new_nickname' => Str::random(256), - ])->assertJsonValidationErrors('new_nickname'); - // Single player option(['single_player' => true]); factory(\App\Models\Player::class)->create(['uid' => $user->uid]);