From a3dff725240d25911b46099652e9176731089f5f Mon Sep 17 00:00:00 2001 From: Craig Childs Date: Mon, 5 Mar 2018 15:43:26 +0000 Subject: [PATCH 1/2] Fixes bug #1259 --- anchor/routes/variables.php | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/anchor/routes/variables.php b/anchor/routes/variables.php index 73727ba88..c2ccad1cc 100755 --- a/anchor/routes/variables.php +++ b/anchor/routes/variables.php @@ -101,31 +101,15 @@ Route::post('admin/extend/variables/edit/(:any)', function ($key) { $input = Input::get(['key', 'value']); - $input['key'] = 'custom_' . slug($input['key'], '_'); - foreach ($input as $key => &$value) { - $value = eq($value); - } + $key = $input['key'] = 'custom_' . slug($input['key'], '_'); + $value = $input['value']; $validator = new Validator($input); - $validator->add('valid_key', function ($str) use ($key) { - - // no change - if ($str == $key) { - return false; - } - - // check the new key $str is available - return Query::table(Base::table('meta')) - ->where('key', '=', $str) - ->count() != 0; - }); - // include prefix length 'custom_' $validator->check('key') - ->is_max(8, __('extend.name_missing')) - ->is_valid_key(__('extend.name_exists')); + ->is_max(8, __('extend.name_missing')); if ($errors = $validator->errors()) { Input::flash(); From 70642448df8c010377fb0789ae3f8fe3ffb8bb3c Mon Sep 17 00:00:00 2001 From: Craig Childs Date: Mon, 5 Mar 2018 16:20:01 +0000 Subject: [PATCH 2/2] Re-add validation. Update composer deps. --- anchor/routes/variables.php | 24 +++++++++++++++++++----- composer.lock | 20 ++++++++++---------- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/anchor/routes/variables.php b/anchor/routes/variables.php index c2ccad1cc..cfb329e00 100755 --- a/anchor/routes/variables.php +++ b/anchor/routes/variables.php @@ -100,16 +100,30 @@ }); Route::post('admin/extend/variables/edit/(:any)', function ($key) { - $input = Input::get(['key', 'value']); + $input = Input::get(['key', 'value']); - $key = $input['key'] = 'custom_' . slug($input['key'], '_'); - $value = $input['value']; + $original = slug($input['key'], '_'); $validator = new Validator($input); - // include prefix length 'custom_' + $validator->add('valid_key', function ($str) use ($original) { + + // Don't check against the same key + if ($str == $original) { + return true; + } + + return Query::table(Base::table('meta')) + ->where('key', '=', $str) + ->count() == 0; + }); + $validator->check('key') - ->is_max(8, __('extend.name_missing')); + ->is_max(1, __('extend.name_missing')) + ->is_valid_key(__('extend.name_exists')); + + $key = $input['key'] = 'custom_' . $original; + $value = $input['value']; if ($errors = $validator->errors()) { Input::flash(); diff --git a/composer.lock b/composer.lock index 368cefab5..758614186 100644 --- a/composer.lock +++ b/composer.lock @@ -496,16 +496,16 @@ }, { "name": "symfony/console", - "version": "v3.4.4", + "version": "v3.4.5", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "26b6f419edda16c19775211987651cb27baea7f1" + "reference": "067339e9b8ec30d5f19f5950208893ff026b94f7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/26b6f419edda16c19775211987651cb27baea7f1", - "reference": "26b6f419edda16c19775211987651cb27baea7f1", + "url": "https://api.github.com/repos/symfony/console/zipball/067339e9b8ec30d5f19f5950208893ff026b94f7", + "reference": "067339e9b8ec30d5f19f5950208893ff026b94f7", "shasum": "" }, "require": { @@ -561,20 +561,20 @@ ], "description": "Symfony Console Component", "homepage": "https://symfony.com", - "time": "2018-01-29T09:03:43+00:00" + "time": "2018-02-26T15:46:28+00:00" }, { "name": "symfony/debug", - "version": "v4.0.4", + "version": "v4.0.5", "source": { "type": "git", "url": "https://github.com/symfony/debug.git", - "reference": "c77bb31d0f6310a2ac11e657475d396a92e5dc54" + "reference": "1721e4e7effb23480966690cdcdc7d2a4152d489" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/debug/zipball/c77bb31d0f6310a2ac11e657475d396a92e5dc54", - "reference": "c77bb31d0f6310a2ac11e657475d396a92e5dc54", + "url": "https://api.github.com/repos/symfony/debug/zipball/1721e4e7effb23480966690cdcdc7d2a4152d489", + "reference": "1721e4e7effb23480966690cdcdc7d2a4152d489", "shasum": "" }, "require": { @@ -617,7 +617,7 @@ ], "description": "Symfony Debug Component", "homepage": "https://symfony.com", - "time": "2018-01-18T22:19:33+00:00" + "time": "2018-02-28T21:50:02+00:00" }, { "name": "symfony/polyfill-mbstring",