provide control over forward slash character
drpitch - November 26, 2007 - 07:54
| Project: | Pathauto |
| Version: | 6.x-2.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | reviewed & tested by the community |
Description
Hello,
In 5.x-1.x version, when I used a forward slash in title nodes, pathauto replaced it by separator character.
But in 5.x-2.x version, forward slash is always removed. There's no way to tell what you want to do with that slashes (forward slash character is not included in the punctuation control area)
For example, how can I make a forward slash is replaced by the separator character?
Thanks.

#1
I agree that the admin should have control of this.
The trick is that all strings are passed through the same cleaning function, so pathauto has to be smart about whether or not it strips out the forward slash when it is dealing with termpath or bookpath etc.
#2
I second this.
Removal of the slashes results in undesirable "glueing" in URLs. It would be much appreciated, if the slashes would be replaced by another character, instead of simply being removed.
#3
Assigning to myself to indicate I want it done for 5.x-2.1.
#4
Great!
#5
+1
#6
Sorry for leaving my name on this. I re-prioritized and don't have time for this now.
#7
Anyone working on this? I hate the forward slash being removed, would love the option to choose to the regular separator instead.
#8
I've put together a trivial patch that fixes this for the 2.2 release. Hopefully that pokes this enough to get this ticket closed in some manner :-)
#9
#10
The problem with this approach is that it doesn't work for people who use termpath nor catpath nor termalias nor bookpath (etc.)
Thanks for the idea, though!
#11
This is what I changed on lines 235 and 236 so that my taxonomy paths looked good when there was a slash in the term names. You could do something similar.
$values[$label .'path'] = $catpath .'/'. check_plain(preg_replace('/\//', '', $category->name));
$values[$label .'path-raw'] = $catpath_raw .'/'. preg_replace('/\//', '', $category->name);
#12
@abv - Works great for termpath/catpath - but not for bookpath etc.
#13
It'd be a great feature for Drupal 6 as well.
#14
Here's a new patch for 6.x that adds in the ability to replace forward slashes. In my (limited) testing, it handles the special cases for menu and taxonomy paths (my changes just piggyback on the code that already skips replacement of slashes in those cases). Please test and let's get this into the next release...
#15
I agree, this is important functionality.
Applying the following to Path Auto 6.x-2.x-dev fails:
patch < pathauto-slash-replacements.patch
patching file pathauto.inc
Hunk #1 succeeded at 192 with fuzz 2 (offset 51 lines).
Hunk #2 FAILED at 204.
Hunk #3 succeeded at 468 (offset -3 lines).
Hunk #4 succeeded at 553 (offset 51 lines).
1 out of 4 hunks FAILED -- saving rejects to file pathauto.inc.rej
#16
Joshua's patch was not made based on current HEAD version of pathauto.inc. I've fixed that.
Also fixed another bug: Joshua deleted the original slash removing code.
I mean this one:
// If something is already urlsafe then don't remove slashesif ($clean_slash) {
$output = str_replace('/', '', $output);
}
However with his patch if the function gets $clean_slash=TRUE parameter and the punctuation rule for slashes is set by the user as action=2 (no action, do not replace), then slashes will be kept in the string, which is wrong (since the function parameter $clean_slash has to be favoured over user's setting for slash handling).
I've fixed this one too (by putting back the original slash replacer code) and attached revised patch. Of course the fix could have been done differently too, but this seemed to be the better choice.
#17
I've changed the status to "reviewed and tested".
I'm not sure whether a single review+test is sufficient for this status change, but unfortunately this patch did not get much attention from anyone else in recent months and I don't think we should wait another 3-4 months til someone else tests it too ...
#18
I don't think that $clean_slash should have precedence. $clean_slash is set to FALSE for e.g. menupath or menupath-raw. But if I *want* the slash to be replaced, it *should* be replaced. Otherwise the patch gives not really any control to most situations...
#19
bump.
Any updates on this being included in the next release? Or someone else testing the patch?
#20
A small addition, I see a strange difference in handling "/" slashes from different other modules (without patches):
- [menupath-raw] (in token_node.inc in the token module) has "/" slashes that are NOT stripped
- [menu-trail-parents-raw] (in menutrails.module in the menutrails project) has "/" slashes that ARE stripped
How is this possible? Why aren't token module's own tokens stripped from slashes, but others are?
#21
Sorry, but the latest patch from #16 does not help preventing slash / removal from the [menu-trail-parents-raw] token from menutrails.module:
1. [menu-trail-parents-raw] contains for example "Solutions/Ecommerce", I checked the $tokens['menu-trail-parents-raw'] = implode('/', $trail_raw); - its good
2. Using patch from #16, slashes / still being removed from [menu-trail-parents-raw]
3. Using patch from #16, now with setting / to "no action", but slashes STILL removed
No effect from the patch, because the culprit is in:
function pathauto_clean_token_values($full) {
...
return $full->values;
}
This function strips all slashes from all tokens that are not "path", "path-raw" or "alias". So what would be the solution? I shall instruct menutrails people to call their tokens something else, with -"path" included.
#22
#23
+1
#24
This works with custom tokens too; add "path" in the token name if you want to keep your forward slashes.
#25
Is there a solution to this issue yet?
#26
Subscribe
#27
Bump
#28
Has menutrails been fixed yet?
#29
I'm having similar issues with the Hierarchical Select module (6.x-3.x-dev), Pathauto (6.x-1.1), and Token (6.x-1.12).
Using token: [save-lineage-termpath-raw:vid] I get a hyphen separating terms: parent-child
So, in template.php I set:
variable_set('hs_taxonomy_separator', '/');It is joining the terms together without the / (slash): parentchild NOT parent/childI've also tried hacking the hs_taxonomy.module and setting:
$separator = '/';with same results.How do I put the slash between the terms? It seems Pathauto keeps dropping it.
#30
The solution I found for #29 was on line 452:
<?phpif (drupal_substr($full->tokens[$key], -4, 4) === 'path' || drupal_substr($full->tokens[$key], -8, 8) === 'path-raw' || drupal_substr($full->tokens[$key], -5, 5) === 'alias') {
?>
<?phpif (strpos($full->tokens[$key], 'path') !== FALSE || strpos($full->tokens[$key], 'alias') !== FALSE) {
?>
I'm not sure if there was a reason
drupal_substrwas being used, whenstrposseemed to accomplish the task quite nicely....drupal_substronly looks at the ends of the strings, but we needed to find "path" wherever it was--strposallowed for a trailing :vid.