When using the path token for a nodereference value, the output link begins with two forward slashes

Title:
[field_project-title-raw]

Path:
[field_project-path]

Resulting link:
//projects/53



I 'fixed' this in my instance by preceding the token with a period, so that the path is "/./projects/53"

CommentFileSizeAuthor
#3 double_slash_fix_61.diff731 bytesMGN
#3 double_slash_fix_62.diff860 bytesMGN
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

MGN’s picture

Status: Active » Postponed (maintainer needs more info)

These kinds of problems are usually due to the specific token, and the module that creates them, unless you see it happening all the time (with or without tokens).

Custom breadcrumbs just uses the value returned by the token, it doesn't create it or modify it, so if one token type is acting up, there is probably a problem in the module that is providing the token.

What version of cck are you using, and have you checked the issue queue for cck on this?

gapple’s picture

Status: Postponed (maintainer needs more info) » Active

I did some code digging, as I use the same token for a couple of Pathauto aliases but didn't have the same issue with double forward slashes appearing.

It looks like the CCK token returns the path with an initial forward slash, and custom_breadcrumbs_nodeapi() through l() and url() will always prepend a forward slash to the path, resulting in the initial double slash.

Pathauto performs some cleanup of the generated aliases to ensure this doesn't happen:
pathauto.inc

function pathauto_create_alias(...)
...
  // Two or more slashes should be collapsed into one
  $alias = preg_replace('/\/+/', '/', $alias);

  // Trim any leading or trailing slashes
  $alias = preg_replace('/^\/|\/+$/', '', $alias);
...

I also thought more about my preceding period fix, and while it will work for anyone with drupal installed at root, it could cause problems otherwise. I think the result would be "/{subfolder}/./{subfolder}/projects/53" which would resolve to the path /subfolder/subfolder/project/53

MGN’s picture

Version: 6.x-1.4 » 6.x-1.x-dev
Status: Active » Needs review
FileSize
860 bytes
731 bytes

Thanks. I've used the snippet above to collapse a double slash to a single slash. The patches below are rolled against 6.x-1.x-dev (double_slash_fix_61.diff) and 6.x-2x-dev (double_slash_fix_62.diff). I would appreciate it if people using the [field_*] cck tokens could test and make sure that this doesn't cause any unanticipated problems.

Thanks

Martynov-1’s picture

Hello,
I installed the patch manually and tested it. But it still doesn't work. And again the module ignores [site-url] placeholder token in "Paths" field but works well with it in "Titles" field. Maybe I did something wrong because this is the first patch in Drupal that I installed. Therefore additional testing is needed.

MGN’s picture

I didn't add the code to trim the leading slash. Since you are patching manually, can you just add one more line to the _custom_breadcrumbs_create_crumb function? It should read

   // Collapse double slashes to one. 
   $original_path = preg_replace('/\/+/', '/', $original_path);
   $original_path = preg_replace('/^\/|\/+$/', '', $original_path);  // add this line
   list($identifier, $path) = explode("|", $original_path, 2);

I can post a real patch if you like, but this might be just as good for now.

Martynov-1’s picture

Thank you very much! Now it works!

MGN’s picture

Status: Needs review » Fixed

Thanks for testing. Committed to 6.x-1.x-dev and 6.x-2.x-dev.

Status: Fixed » Closed (fixed)

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