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

greggles - November 26, 2007 - 14:29
Title:Forward slashes always removed» provide control over forward slash character
Category:bug report» feature request

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

groenm - December 7, 2007 - 16:00

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

greggles - December 17, 2007 - 12:01
Assigned to:Anonymous» greggles

Assigning to myself to indicate I want it done for 5.x-2.1.

#4

drpitch - December 18, 2007 - 11:57

Great!

#5

bobdalob - March 2, 2008 - 13:16

+1

#6

greggles - March 3, 2008 - 14:39
Assigned to:greggles» Anonymous

Sorry for leaving my name on this. I re-prioritized and don't have time for this now.

#7

cs8c - March 13, 2008 - 00:40

Anyone working on this? I hate the forward slash being removed, would love the option to choose to the regular separator instead.

#8

xxvelcrar - May 9, 2008 - 22:05

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 :-)

AttachmentSize
pathauto-2.2.slash_.patch 1.11 KB

#9

xxvelcrar - May 9, 2008 - 22:06
Status:active» needs review

#10

greggles - May 9, 2008 - 23:45
Status:needs review» needs work

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

abv - August 20, 2008 - 18:33

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

greggles - August 20, 2008 - 20:13

@abv - Works great for termpath/catpath - but not for bookpath etc.

#13

mike_r1977 - October 7, 2008 - 08:23

#14

joshuajabbour - October 28, 2008 - 02:59
Version:5.x-2.x-dev» 6.x-2.x-dev

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...

AttachmentSize
pathauto-slash-replacements.patch 1.97 KB

#15

markj - November 29, 2008 - 00:42

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

müzso - March 1, 2009 - 12:14

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 slashes
  if ($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.

AttachmentSize
pathauto-slash-replacements-2.patch 1.57 KB

#17

müzso - March 1, 2009 - 12:16
Status:needs work» reviewed & tested by the community

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

Frank Steiner - March 11, 2009 - 07:41

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

rcross - April 23, 2009 - 02:15

bump.

Any updates on this being included in the next release? Or someone else testing the patch?

#20

morningtime - April 25, 2009 - 08:25

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

morningtime - April 25, 2009 - 08:39
Status:reviewed & tested by the community» needs work

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

morningtime - April 25, 2009 - 08:39
Status:needs work» reviewed & tested by the community

#23

bit7 - July 3, 2009 - 15:01

+1

#24

seancr - August 4, 2009 - 10:51

This works with custom tokens too; add "path" in the token name if you want to keep your forward slashes.

#25

mizerydearia - September 21, 2009 - 23:51

Is there a solution to this issue yet?

#26

TravisCarden - October 1, 2009 - 04:48

Subscribe

#27

drpitch - October 5, 2009 - 21:54

Bump

#28

greggles - October 5, 2009 - 23:24

Has menutrails been fixed yet?

#29

dcasey - October 13, 2009 - 19:31

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/child

I'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

bobzillaforever - November 6, 2009 - 22:10

The solution I found for #29 was on line 452:

<?php
if (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') {
?>

<?php
if (strpos($full->tokens[$key], 'path') !== FALSE || strpos($full->tokens[$key], 'alias') !== FALSE) {
?>

I'm not sure if there was a reason drupal_substr was being used, when strpos seemed to accomplish the task quite nicely.... drupal_substr only looks at the ends of the strings, but we needed to find "path" wherever it was--strpos allowed for a trailing :vid.

AttachmentSize
pathauto-clean_token-patch.txt 914 bytes
 
 

Drupal is a registered trademark of Dries Buytaert.