drupal_substr("test", 0, 0) returns "t"
substr("test", 0, 0) returns ""

as far as I understand it's a bug as drupal_substr is utf8 safe substr clone.

the problem can cause problems with code like

 while (strpos($node->title, '"') !== FALSE) { 
      $w = (!$w || $w == '»') ? $w = '«' : $w = '»';          
      $pos = strpos($node->title, '"');
      if ($pos !== FALSE) {
        $node->title = drupal_substr($node->title, 0, $pos) . $w . drupal_substr($node->title, $pos + 1);
      }       
    }  

(I got infinite loop as first symbol couldn't be replaced)

simple patch attached

Comments

gpk’s picture

Version: 6.6 » 7.x-dev
Status: Needs review » Needs work

Will need to be fixed first in HEAD, and also have tests written.

restyler’s picture

Status: Needs work » Needs review
StatusFileSize
new376 bytes

patch for 7.x branch attached

restyler’s picture

StatusFileSize
new1.39 KB

I'm not sure that I've done everything correctly, but here is the test

damien tournoud’s picture

Status: Needs review » Closed (duplicate)