Skip to content

[FIX] accept headers was not being respected because of errorneous strpos needle/haystack parameters

Should be backported to Tiki 19 and 18 too.

[FIX] accept headers was not being respected because of errorneous strpos needle/haystack parameters

This bug was discovered as I was trying to use the Tiki AJAX Services in lib/core/Services in an API way, ie. instead of getting the rendered version based on the matching tpl for that service, I wanted to get the raw JSON. Looking at the code in lib/core/Services/Broker.php->process, I noticed this was already handled in pretty much an industry standard way, following

if ($access->is_serializable_request()) {
    echo $access->output_serialized($output);
} else {
    TikiLib::events()->trigger('tiki.process.render');
    echo $this->render($controller, $action, $output, $request);
}

and looking in lib/tikiaccesslib.php->is_serializable_request() which calls lib/tikiaccesslib.php->get_accept_types it does check $_SERVER['HTTP_ACCEPT'] which is the Accept: HTTP header that is being passed from an AJAX request. This is the industry standard way to request JSON from an AJAX request, by specifying

Accept: 'application/json; charset=utf-8'

However, although the code looked like it's handling it, it didn't work. On further investigation, it turns out that the strpos parameters for the haystack and needle was switched, hence none of the if statements were coming up true. This fixes it.

Merge request reports