1
0
Fork 0
mirror of synced 2024-06-25 17:50:38 +12:00

Limit key size to 32 chars

This commit is contained in:
Eldad Fux 2020-06-11 00:42:16 +03:00
parent 1997fd7b5e
commit 1f8cd7f081
3 changed files with 43 additions and 3 deletions

View file

@ -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>

View file

@ -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;
}

View file

@ -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);
}
}