The fix committed in #1395548: services_resource_build_index_query provides no way of querying values with commas endlessly loops on PHP 5.2 machines (which don't have str_getcsv())

Reproduce with http://localhost/api/user?parameters[name]=12345

Downgrading services from dev to stable fixed the issue.

Comments

kylebrowning’s picture

if (!function_exists('str_getcsv')) {
should stop it from running on a machine that doesn't have it.

Are you sure thats where the problem lies?

kylebrowning’s picture

Assigned: Unassigned » kylebrowning

oh i guess my bad I read that code wrong. THere is a ! in front of it.

Ill look into it.

djdevin’s picture

Thanks, the while() loop never ends. There's a few replacements for str_getcsv in PHP 5.2, maybe that one just doesn't work.

Grabbed the str_getcsv replacement and threw it into PHP, just to make sure it wasn't anything in Drupal:

<?php
$string = "12345";

    $temp = fopen("php://memory", "rw");
    fwrite($temp, $string);
    fseek($temp, 0);
// endless loop
    while (($data = fgetcsv($temp, 0, $delimiter, $enclosure, $escape)) !== false) {
      $ret[] = $data;
    }
    fclose($temp);

print_r($ret);
djdevin’s picture

Got it - in PHP 5.2 the last argument ($escape) doesn't exist, triggering a function warning.

Remove $escape and it seems to work.

djdevin’s picture

Status: Active » Needs review
StatusFileSize
new488 bytes

Patch for the record.

marcingy’s picture

Version: 6.x-3.x-dev » 7.x-3.x-dev
Status: Needs review » Reviewed & tested by the community

This needs to be fixed in d7 first - assuming the patch applies cleanly and marking as RTBC

djdevin’s picture

Status: Reviewed & tested by the community » Needs review

Now that I think about it, I think this still might be wrong in both versions for PHP 5.2

str_getcsv returns an indexed array of fields (1 row). But, the PHP 5.2 equivalent seems to be returning a nested indexed array of fields (multiple rows)...right?

djdevin’s picture

StatusFileSize
new474 bytes

I think it should be something like this instead.

Status: Needs review » Needs work

The last submitted patch, 1569376-services-str_getcsv-loop-8.patch, failed testing.

djdevin’s picture

StatusFileSize
new520 bytes

Patch for 7x

djdevin’s picture

Status: Needs work » Needs review
franz’s picture

Status: Needs review » Reviewed & tested by the community

Patch on #10 worked well for me.

ygerasimov’s picture

Thank you a lot for the patch.

kylebrowning’s picture

Status: Reviewed & tested by the community » Fixed
djdevin’s picture

Can we port this to 6.x-3.x too? Fix should be the same.

ygerasimov’s picture

Committed to 6.x-3.x branch.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.