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
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | substr_test.patch | 1.39 KB | restyler |
| #2 | substr_fix_d7.patch | 376 bytes | restyler |
| drupal_substr_fix.patch | 320 bytes | restyler |
Comments
Comment #1
gpk commentedWill need to be fixed first in HEAD, and also have tests written.
Comment #2
restyler commentedpatch for 7.x branch attached
Comment #3
restyler commentedI'm not sure that I've done everything correctly, but here is the test
Comment #4
damien tournoud commentedThis is now superseded by #352359: [core] Fixes for drupal_strpos().