When the REST server tries to render an empty response body in YAML, a PHP error is generated:

Invalid argument supplied for foreach() in sites/all/modules/services/servers/rest_server/lib/spyc.php on line 167.

This would come up, for instance, from the services error resulting from failed session authentication. The Spyc class expects an array and it doesn't check if the supplied argument is null before diving into the loop. Attached is a possible solution.

CommentFileSizeAuthor
yaml_rendering.patch647 byteskevin.dutra

Comments

marcingy’s picture

Status: Active » Postponed
ygerasimov’s picture

Status: Postponed » Active

@kevin.dutra will following simple code work?

private function render_yaml($data) {
     module_load_include('php', 'rest_server', 'lib/spyc');
+    $data = (array)$data;
     return Spyc::YAMLDump($data, 4, 60);
   }

Could you please test?

As I understand issue #1325572 won't change the behavior of the bug.

marcingy’s picture

Version: 6.x-3.x-dev » 7.x-3.x-dev
Issue tags: +needs backport to 6.x

Needs be fixed in d7 first

kevin.dutra’s picture

@ygerasimov
Yes, it looks like the type cast also works. I didn't realize that casting null to array would yield an empty array, so I'll have to file that one away in the back of my brain somewhere :)

kylebrowning’s picture

So what are we doing here?

cotto’s picture

Note that #1313976: upgrade SPYC to latest version would fix this issue too.

marcingy’s picture

Status: Active » Postponed

We are removing this library #1325572: Integrate services with the libraries module to improve handling of third party libraries. very soon as it should not be in the repo. Marking as postponed as the the efforts should be placed on the other issue - note you can update to the new version spyc if you wish right now.

marcingy’s picture

Status: Postponed » Closed (won't fix)

Libraries no longer ship with services