Use drupal_str functions instead of str functions

Freso - May 23, 2008 - 17:11
Project:Pathauto
Version:5.x-2.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed
Description

Pathauto is currently using a bunch of strtolower(), strlen(), and other string functions that have drupal_ equivalents. We should probably use the drupal_ version for most (if not all) of these instances. (If someone gets around to it before I do, here's a hint: Use Coder to find the instances. :))

I'm also going mark this as blocking the release of 6.x-1.1.

#1

Freso - May 24, 2008 - 11:29
Status:active» needs review

Is there a reason these instances were not using the drupal_ functions? (Attached patch has not been tested.)

AttachmentSize
pathauto_use_drupal_str_functions.d6.patch 2.65 KB

#2

greggles - May 24, 2008 - 20:34

No reason that I know. I think I just didn't know about the drupal_*str* set of functions. This seems RTBC to me.

#3

greggles - May 25, 2008 - 16:36
Status:needs review» reviewed & tested by the community

I gave this some testing and, though I found some other bugs, I don't think this introduces any bugs (my testing and the simpletests still work as expected).

#4

Freso - May 25, 2008 - 20:37
Version:6.x-1.x-dev» 5.x-2.x-dev
Status:reviewed & tested by the community» patch (to be ported)

Alright then, committed. :) It should probably be backported though.

#5

Freso - May 25, 2008 - 20:48
Status:patch (to be ported)» fixed

The patch more-or-less applied to 5.x (one failed hunk, some offset), so committed there as well.

I also stumbled upon an empty for-loop while applying the failed hunk:

<?php
   
for ($i = 0; _pathauto_alias_exists(drupal_substr($alias, 0, $maxlength - drupal_strlen($i)) . $separator . $i, $src); $i++) {
    }
?>

This should probably be investigated for another (clean-up =)) patch... (It exists in both D5 and D6 versions.)

#6

greggles - May 25, 2008 - 20:59

I think the empty for loop is just a way to keep trying new aliases until we get one that's unique. It's perhaps an overly fancy/brief construction which is difficult to understand (I didn't write it and I still have to think about what it does to see if it works).

#7

Freso - May 25, 2008 - 21:08

From what I can see, nothing is done during the loop - not while calculating the criteria, not while actually running it! If it does anything, it's using time/CPU cycles. But then, perhaps you're seeing something I'm not. ... And then I realised it's making and storing a count in $i, which is used just a bit later... This is definitely worthy of a code comment. Before we forget what it is. :)

#8

Freso - May 25, 2008 - 21:12

And since $i will always be an integer, we can safely use PHP's own strlen on it, for speed. So I'll reverse this bit.

#9

Anonymous (not verified) - June 8, 2008 - 21:22
Status:fixed» closed

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

 
 

Drupal is a registered trademark of Dries Buytaert.