mikealmond / MusicBrainz

A PHP library to access MusicBrainz's Web Service v2
http://musicbrainz.org/doc/Development
MIT License
64 stars 26 forks source link

RecordingFilter does not apply urlencode to filter arguments #24

Open codebucketdev opened 7 years ago

codebucketdev commented 7 years ago

When using RecordingFilter to search for tracks on MusicBrainz without urlencode, it throws an Exception back with wrong results.

$filter = array(
  "artist" => $artist,
  "recording" => $track
);

$recordings = $this->brainz->search(new RecordingFilter($filter));

Result:

GET /test.php?track=What%20I%27ve%20Been%20Waiting%20For%20(feat.%20D.%20Brown)&artist=Vicetone HTTP/1.1
Host: coverart.localhost
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: de,en-US;q=0.7,en;q=0.3
Accept-Encoding: gzip, deflate
DNT: 1
Connection: keep-alive
Upgrade-Insecure-Requests: 1
Cache-Control: max-age=0

Notice: Undefined index: releases in C:\XAMPP\htdocs\coverart\vendor\mikealmond\musicbrainz\src\MusicBrainz\Recording.php on line 47

Catchable fatal error: Argument 1 passed to MusicBrainz\Recording::setReleases() must be of the type array, null given, called in C:\XAMPP\htdocs\coverart\vendor\mikealmond\musicbrainz\src\MusicBrainz\Recording.php on line 47 and defined in C:\XAMPP\htdocs\coverart\vendor\mikealmond\musicbrainz\src\MusicBrainz\Recording.php on line 55

But after applying urlencode to the filter args, the search works just fine!

$filter = array(
  "artist" => urlencode($artist),
  "recording" => urlencode($track)
);

$recordings = $this->brainz->search(new RecordingFilter($filter));

Result:

GET /test.php?track=What%20I%27ve%20Been%20Waiting%20For%20(feat.%20D.%20Brown)&artist=Vicetone HTTP/1.1
Host: coverart.localhost
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: de,en-US;q=0.7,en;q=0.3
Accept-Encoding: gzip, deflate
DNT: 1
Connection: keep-alive
Upgrade-Insecure-Requests: 1
Cache-Control: max-age=0

[
    {
        "id": "5e46d9dd-3ce4-4a0b-8194-7e10919e2fcb",
        "title": "What I've Waited For",
        "score": 100,
        "releases": [
            {
                "id": "c11b3169-aedd-4bbe-a612-e7ad484dc350",
                "title": "Monstercat 020: Altitude",
                "status": "Official",
                "quality": "",
                "language": "",
                "script": "",
                "date": "2014-12-15",
                "country": "XW",
                "barcode": "",
                "artists": [],
                "brainz": {}
            },
            {
                "id": "a1b74b08-864d-48f4-bb3c-f68ba651fca1",
                "title": "Monstercat - Best of 2014",
                "status": "Official",
                "quality": "",
                "language": "",
                "script": "",
                "date": "2015-01-26",
                "country": "XW",
                "barcode": "",
                "artists": [],
                "brainz": {}
            }
        ],
        "brainz": {},
        "length": 221000,
        "artistID": "cc91bb2e-7330-4f9e-ae04-4f78f49e3155"
    }
]