mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Limit key size to 32 chars
This commit is contained in:
@@ -251,7 +251,7 @@ $rules = $collection->getAttribute('rules', []);
|
||||
<span class="tooltip small" data-tooltip="Attribute key name. Used as the document JSON key in the Database API"><i class="icon-info-circled"></i></span>
|
||||
</label>
|
||||
<div class="input-copy">
|
||||
<input data-forms-copy name="key" type="text" data-ls-bind="{{rule.key}}" max="32" pattern="^(\d|\w)+$" title="No spaces or special charts allowed" />
|
||||
<input data-forms-copy name="key" type="text" data-ls-bind="{{rule.key}}" maxlength="32" pattern="^(\d|\w)+$" title="No spaces or special charts allowed" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -404,7 +404,7 @@ $rules = $collection->getAttribute('rules', []);
|
||||
<span class="tooltip small" data-tooltip="Attribute key name. Used as the document JSON key in the Database API"><i class="icon-info-circled"></i></span>
|
||||
</label>
|
||||
<div class="input-copy">
|
||||
<input data-forms-copy name="key" type="text" required max="32" pattern="^(\d|\w)+$" title="No spaces or special charts allowed" />
|
||||
<input data-forms-copy name="key" type="text" required maxlength="32" pattern="^(\d|\w)+$" title="No spaces or special charts allowed" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -34,11 +34,15 @@ class Key extends Validator
|
||||
*/
|
||||
public function isValid($value)
|
||||
{
|
||||
if(!is_string($value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (preg_match('/[^A-Za-z0-9\-\_]/', $value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mb_strlen($value) > 40) {
|
||||
if (mb_strlen($value) > 32) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace Appwrite\Tests;
|
||||
|
||||
use Appwrite\Database\Validator\Key;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class KeyTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var Key
|
||||
*/
|
||||
protected $object = null;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->object = new Key();
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
public function testValues()
|
||||
{
|
||||
$this->assertEquals($this->object->isValid('dasda asdasd'), false);
|
||||
$this->assertEquals($this->object->isValid('asdasdasdas'), true);
|
||||
$this->assertEquals($this->object->isValid('as$$5dasdasdas'), false);
|
||||
$this->assertEquals($this->object->isValid(false), false);
|
||||
$this->assertEquals($this->object->isValid(null), false);
|
||||
$this->assertEquals($this->object->isValid('socialAccountForYoutubeSubscribers'), false);
|
||||
$this->assertEquals($this->object->isValid('socialAccountForYoutubeSubscriber'), false);
|
||||
$this->assertEquals($this->object->isValid('socialAccountForYoutubeSubscribe'), true);
|
||||
$this->assertEquals($this->object->isValid('socialAccountForYoutubeSubscrib'), true);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user