]> source.dussan.org Git - nextcloud-server.git/commitdiff
Dont set null values when validating storage definition
authorRobin Appelman <icewind@owncloud.com>
Tue, 26 Jan 2016 13:40:55 +0000 (14:40 +0100)
committerRobin Appelman <icewind@owncloud.com>
Fri, 29 Jan 2016 13:51:30 +0000 (14:51 +0100)
apps/files_external/lib/definitionparameter.php
apps/files_external/lib/frontenddefinitiontrait.php
apps/files_external/tests/frontenddefinitiontraittest.php

index 85c3dd08ad423eb84a925cf6631140ab32c436d6..dc7985837f54f696ca98963aa893d0a9c8c88775 100644 (file)
@@ -154,6 +154,10 @@ class DefinitionParameter implements \JsonSerializable {
                return $prefix . $this->getText();
        }
 
+       public function isOptional() {
+               return $this->isFlagSet(self::FLAG_OPTIONAL) || $this->isFlagSet(self::FLAG_USER_PROVIDED);
+       }
+
        /**
         * Validate a parameter value against this
         * Convert type as necessary
@@ -162,8 +166,6 @@ class DefinitionParameter implements \JsonSerializable {
         * @return bool success
         */
        public function validateValue(&$value) {
-               $optional = $this->isFlagSet(self::FLAG_OPTIONAL) || $this->isFlagSet(self::FLAG_USER_PROVIDED);
-
                switch ($this->getType()) {
                        case self::VALUE_BOOLEAN:
                                if (!is_bool($value)) {
@@ -180,7 +182,7 @@ class DefinitionParameter implements \JsonSerializable {
                                }
                                break;
                        default:
-                               if (!$value && !$optional) {
+                               if (!$value && !$this->isOptional()) {
                                        return false;
                                }
                                break;
index eedd433f2d7658b59492fe567f23c98619445af4..fc47a9515f3223471913f422457252ef5fe03593 100644 (file)
@@ -136,10 +136,12 @@ trait FrontendDefinitionTrait {
        public function validateStorageDefinition(StorageConfig $storage) {
                foreach ($this->getParameters() as $name => $parameter) {
                        $value = $storage->getBackendOption($name);
-                       if (!$parameter->validateValue($value)) {
-                               return false;
+                       if (!is_null($value) || !$parameter->isOptional()) {
+                               if (!$parameter->validateValue($value)) {
+                                       return false;
+                               }
+                               $storage->setBackendOption($name, $value);
                        }
-                       $storage->setBackendOption($name, $value);
                }
                return true;
        }
index 209b1abc7e0dd4f0b866b53f4af13cc757a987f6..27f49556330829475c3ff101981989151012d1f2 100644 (file)
@@ -61,6 +61,8 @@ class FrontendDefinitionTraitTest extends \Test\TestCase {
                                ->getMock();
                        $param->method('getName')
                                ->willReturn($name);
+                       $param->method('isOptional')
+                               ->willReturn(false);
                        $param->expects($this->once())
                                ->method('validateValue')
                                ->willReturn($valid);