(406) $url = str_replace('?q=', '', ltrim($url, base_path())); sometimes breaks urls (if url begins with one of the base_path()'s char) , i think something like $url = str_replace('?q=', '',ereg_replace(base_path(),$url)); will be better.

Hope it helps
David

Comments

jsloan’s picture

This bug bit me today and in looking through the process I found that your suspicion is correct.

The problem is that when using ltrim() it will continue its replacement until it encounters a character that is not in the $charlist of the second parameter. http://us2.php.net/ltrim This is not a substring replacement function it is a "trim" using any character in the supplied list.

I suggest using preg_replace() instead of ereg_replace() and adding the limit to equal 1 so that it only removes the beginning of the URL.

  //echo preg_replace( "!".base_path()."!", "", $url,1 );
  $url = str_replace('?q=', '', preg_replace( "!".base_path()."!", "", $url,1 ));

I think that this line should be refactored to unravel its complexity. I'll try to submit a patch later.

jsloan’s picture

StatusFileSize
new453 bytes

... here's a patch.

cburschka’s picture

Status: Active » Needs review

Issues with patches should be flagged accordingly to avoid falling under the radar.

I can't test this, but both the problem and the fix look fairly straightforward. ltrim() is really just wrong for this purpose, as mentioned - ltrim()'s second parameter is not a string to remove, it's simply a blacklist of trimmable characters. That it succeeds is a matter of luck.

Analogy: ltrim("apples/bananas","apples/") -> "bananas" works (by chance!), but
ltrim("bakery/bananas","bakery/") -> "nanas" simply gets nonsensical results.

coltrane’s picture

Patch tested and works correctly.

smithwib’s picture

One additional observation. One of my sites on a Windows box running IIS does not use the RewriteEngine and does not always have clean URLs, so the URLs submitted to _mimemail_url may look like "/?q=services" or "/?q=node/23". What I have found properly adjusts these is to use: $url = preg_replace( "!".base_path()."(index.php)?!", "", $url,1 );

michelle’s picture

Status: Needs review » Reviewed & tested by the community

Fixed the problem I was having with this on a client site. Thanks!

Michelle

jerdavis’s picture

Priority: Normal » Critical
StatusFileSize
new466 bytes

I wasn't able to reproduce the issue on my test site, as I wasn't sure how to configure to reproduce it. I also had a problem applying the patch linked above and as such, i've re-factored it a bit. The included patch file should work. Testing it, I did not see any issues.

jerdavis’s picture

StatusFileSize
new465 bytes

Uploading an updates patch, this patch takes into account the "Code Cleanup" patch from: http://drupal.org/node/220432

This update requires that patch prior to being applied.

allie micka’s picture

Status: Reviewed & tested by the community » Fixed

Committed to HEAD, will roll a D5 release soon. Thanks!

Anonymous’s picture

Status: Fixed » Closed (fixed)

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