Skip to content

Commit

Permalink
Merge pull request #632 from biigle/utf8-bug
Browse files Browse the repository at this point in the history
Resolve Utf8 bug
  • Loading branch information
mzur authored Aug 9, 2023
2 parents 67c3424 + 375da03 commit 772f9f7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/Http/Requests/StoreVolumeMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public function rules()
{
return [
'metadata_csv' => [
'bail',
'required_without_all:metadata_text,ifdo_file',
'file',
'mimetypes:text/plain,text/csv,application/csv',
Expand Down
3 changes: 2 additions & 1 deletion app/Rules/Utf8.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class Utf8 implements Rule
*/
public function passes($attribute, $value)
{
return mb_detect_encoding($value->get(), 'UTF-8', true) !== false;
$value = is_string($value) ? $value : $value->get();
return mb_detect_encoding($value, 'UTF-8', true) !== false;
}

/**
Expand Down
10 changes: 10 additions & 0 deletions tests/php/Http/Controllers/Api/Volumes/MetadataControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ public function testStoreImageMetadata()
$this->assertEmpty($png->metadata);
}

public function testStoreStringMetadata()
{
$id = $this->volume()->id;

$this->beAdmin();

$this->postJson("/api/v1/volumes/{$id}/metadata", ['metadata_csv' => "metadata_string"])
->assertStatus(422);
}

public function testStoreDeprecatedFileAttribute()
{
$id = $this->volume()->id;
Expand Down

0 comments on commit 772f9f7

Please sign in to comment.