nette / schema

📐 Validating data structures against a given Schema.
https://doc.nette.org/schema
Other
886 stars 26 forks source link

Merging default values doesn't work on non associative array. #24

Closed ncou closed 3 years ago

ncou commented 4 years ago

Hi,

I encounter a bug with the merge function when the schema use a list of string. Here is an example :

` $schema = Expect::structure([ 'paths' => Expect::arrayOf('string')->default(['path_1']), ]);

$data = ['paths' => ['path_1']]; ` after the processSchema() i got the following result :

['path_1', 'path_1'] but i expect the values to be merged, and only have ['path_1'] as a result. This wrong behavior is when the array has numeric keys. If a use an associative array (ex : ['default' => 'path_1']) the merge work fine and i got only on element for the result.

Keep up the good work, this library is amazing :)

mabar commented 4 years ago

What would be result if $data = ['paths' => ['path_1', 'path_1', 'path_1']];? Multiple identical values in dataset are not necessarily an error.

ncou commented 4 years ago

yes you got a point, but if there is already 'path_1' in the user value, why add the default value (which is the same). I don't think a unique function should be applyed, i only think it's not really logical to add again the default value while it's already present in the data array.

ncou commented 4 years ago

I think my issue is the same than the ticket https://github.com/nette/schema/issues/13 If it's a duplicate, i will close my ticket.

dg commented 3 years ago

Yes, it is duplicate issue.