html_entity_decode() tags, fixes #323

This commit is contained in:
An Phan 2016-05-05 23:03:30 +08:00
parent f8c7233cd9
commit 68baf5001c
2 changed files with 31 additions and 4 deletions

View file

@ -139,10 +139,11 @@ class File
$lyrics = array_get($comments, 'unsynchronised_lyric', [''])[0]; $lyrics = array_get($comments, 'unsynchronised_lyric', [''])[0];
} }
$props['artist'] = trim($artist); // Fixes #323, where tag names can be htmlentities()'ed
$props['album'] = trim($album); $props['artist'] = html_entity_decode(trim($artist));
$props['title'] = trim($title); $props['album'] = html_entity_decode(trim($album));
$props['lyrics'] = trim($lyrics); $props['title'] = html_entity_decode(trim($title));
$props['lyrics'] = html_entity_decode(trim($lyrics));
return $this->info = $props; return $this->info = $props;
} }

View file

@ -3,10 +3,12 @@
use App\Events\LibraryChanged; use App\Events\LibraryChanged;
use App\Libraries\WatchRecord\InotifyWatchRecord; use App\Libraries\WatchRecord\InotifyWatchRecord;
use App\Models\Album; use App\Models\Album;
use App\Models\File;
use App\Models\Song; use App\Models\Song;
use App\Services\Media; use App\Services\Media;
use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Foundation\Testing\WithoutMiddleware; use Illuminate\Foundation\Testing\WithoutMiddleware;
use Mockery as m;
class MediaTest extends TestCase class MediaTest extends TestCase
{ {
@ -157,4 +159,28 @@ class MediaTest extends TestCase
$this->notSeeInDatabase('songs', ['path' => $this->mediaPath.'/subdir/no-name.MP3']); $this->notSeeInDatabase('songs', ['path' => $this->mediaPath.'/subdir/no-name.MP3']);
$this->notSeeInDatabase('songs', ['path' => $this->mediaPath.'/subdir/back-in-black.mp3']); $this->notSeeInDatabase('songs', ['path' => $this->mediaPath.'/subdir/back-in-black.mp3']);
} }
public function testHtmlEntitiesInTags()
{
$getID3 = m::mock(getID3::class, [
'analyze' => [
'tags' => [
'id3v2' => [
'title' => ['水谷広実'],
'album' => ['小岩井こ Random'],
'artist' => ['佐倉綾音 Unknown'],
],
],
'encoding' => 'UTF-8',
'playtime_seconds' => 100,
],
]);
$file = new File(dirname(__FILE__).'/songs/blank.mp3', $getID3);
$info = $file->getInfo();
$this->assertEquals('佐倉綾音 Unknown', $info['artist']);
$this->assertEquals('小岩井こ Random', $info['album']);
$this->assertEquals('水谷広実', $info['title']);
}
} }