CCK nodereference paths cause invalid links

gapple - August 8, 2009 - 10:57
Project:Custom Breadcrumbs
Version:6.x-1.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed
Description

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"

#1

MGN - August 8, 2009 - 14:55
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?

#2

gapple - August 10, 2009 - 07:41
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

#3

MGN - September 15, 2009 - 01:49
Version:6.x-1.4» 6.x-1.x-dev
Status:active» needs review

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

AttachmentSize
double_slash_fix_61.diff 731 bytes
double_slash_fix_62.diff 860 bytes

#4

Martynov - September 16, 2009 - 23:03

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.

#5

MGN - September 17, 2009 - 11:12

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

<?php
  
// 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.

#6

Martynov - September 17, 2009 - 21:33

Thank you very much! Now it works!

#7

MGN - September 18, 2009 - 13:02
Status:needs review» fixed

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

#8

System Message - October 2, 2009 - 13:10
Status:fixed» closed

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

 
 

Drupal is a registered trademark of Dries Buytaert.