Often times, we are forced to have a very long title name. When that happens, PathAuto often trunkates the path as it should, but it sometimes keeps the trailing space (and converts it to a - as it should)

Possible for PathAuto to delete the trailing slash (trailing -, when its converted)
An example url that PathAuto generates is:
http://www.example.com/press_releases/2008/05/aol-awards-ohio-university...

Steps to repeat:
1. Create a posting. For the title, give it a REALLLYYY LOOONNGGG name.
2. Submit it.

Thanks!

Comments

Freso’s picture

Version: 5.x-2.2 » 5.x-2.x-dev
Status: Active » Postponed (maintainer needs more info)

I just added a lot of pattern trimming to both the 5.x-2.x and 6.x-1.x branches. Could please confirm this is still happening with the 5.x-2.x-dev version? (You may have to wait a bit though, until the "Last updated" field says "June 13" (or later).)

tcconway’s picture

Hey Freso,
Just installed 5.x-2.x-dev and still having the same issue. It still creates a url that ends in "-".
Thanks.

greggles’s picture

Title: Long Title Names - PathAuto trunkates and includes a trailing space » Punctuation character at end of url is left as separator
Status: Postponed (maintainer needs more info) » Active

Steps taken:

1. Create a node with the title Often times, we are forced to have a very long title name. When that happens, PathAuto often trunkates the path as it should, bu
2. Resulting alias was often-times-we-are-forced-to-have-very-long-title-name-when-that-happens-pathauto-often-trunkates-th

That seems as expected to me.

So, I tried
1. Create a node with the title Often times, we are forced to have a very long title name. When that happens, PathAuto often trunkates the path as it (note all of the spaces after trunkates, I expected pathauto to cut the line there and replace the space with hyphen) but...
2. Resulting alias was often-times-we-are-forced-to-have-very-long-title-name-when-that-happens-pathauto-often-trunkates-th

So I tried
1. Create a node with the title Often times, we are forced to have a very long title name. When that happens, PathAuto often trunkates t he path as it (note the space in the middle of the word "the" in "trunkates t he")
2. Resulting alias was often-times-we-are-forced-to-have-very-long-title-name-when-that-happens-pathauto-often-trunkates-t-

So, I'd say that is the bug, right?

tcconway’s picture

Well played. That's exactly what we are experiencing as well.

To me, there are two issues:

  • If the 100th caracter is a space, it doesnt trim it off, but replaces it with a "-" (or whatever the administrator defines as the separator).
  • To me, it should cut off at the last word(s) that go beyond the 100character cutoff...and prevent things like often-times-we-are-forced-to-have-very-long-title-name-when-that-happens-pathauto-often-trunkates-th. Resulting in: often-times-we-are-forced-to-have-very-long-title-name-when-that-happens-pathauto-often-trunkates
Freso’s picture

Hohum. I'm inclined to re-categorise into a feature request for what's described in #4. This also means that I'm inclined to not want to spend time fixing this for 5.x, but have it moved to 6.x-2.x instead.

greggles’s picture

Title: Punctuation character at end of url is left as separator » Break URLs at separator character and remove the separator

@Freso - Agreed.

I've also received several requests that when urls are shortened for whatever reason they should be shortened to a good logical point (i.e. separators) instead of just the exact point where 100 characters lands. Since those seem similar in my mind, I'll just bundle that one in here.

greggles’s picture

Something like http://api.drupal.org/api/function/truncate_utf8 will sure help when we need to do this.

Freso’s picture

Version: 5.x-2.x-dev » 7.x-1.x-dev
Freso’s picture

Category: bug » feature
Status: Active » Needs review
StatusFileSize
new742 bytes

This should work, but I haven't tested it. So please do.

Freso’s picture

Status: Needs review » Needs work

Just tested it, and it doesn't seem to work. Bugger.

greggles’s picture

Status: Needs work » Needs review
StatusFileSize
new1.75 KB

How about this?

Freso’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new1.4 KB

Yay! It works! :D

It had a line of pure whitespace though, so fixed that. I also added a line documenting what that block of code does. Should be good to go.

greggles’s picture

Status: Reviewed & tested by the community » Fixed

Awesome - thanks, Freso.

http://drupal.org/cvs?commit=131526

greggles’s picture

Status: Fixed » Needs work

Per Freso, this needs a little more testing...

greggles’s picture

Status: Needs work » Needs review

The problem was that if you created a node with a short title this still lopped off the last word.

1. Create a node with the title "this is a short title"
Expect results:
aliased as content/this-short-title

Actual results:
aliased as content/this-short

The attached patch fixes that problem, generalizes this code so it can be re-used elsewhere in pathauto, and then re-uses it where individual tokens are built and shortened to the appropriate length.

greggles’s picture

StatusFileSize
new2.21 KB

Attached...now...

Freso’s picture

+1 for separating the logic to its own function, but perhaps call it _pathauto_truncate_url() or truncate_chars instead? (FWIW, the 7.x version of truncate_utf8() will be drupal_truncate_chars().)

Also "A Pathauto friendly version of truncate_utf8" should be finished off with a ".". ;)

Apart from this, the patch looks good. Looking forward to test it in the morrow!

greggles’s picture

StatusFileSize
new2.26 KB

Good points.

Freso’s picture

Status: Needs review » Reviewed & tested by the community

Works now with both long and short aliases! Yay! And I see no more nits to pick at (well, perhaps truncate_utf8 could be referenced with a pair of parentheses... but I'm somewhat indifferent on that). :p

Freso’s picture

Status: Reviewed & tested by the community » Needs work

It breaks the tests though, but this is likely because the tests themselves need to be updated for this new logic.

Freso’s picture

Status: Needs work » Reviewed & tested by the community

Actually, without this follow-up patch, it'll break two tests, but with it, it'll only break one. So it's an improvement. The test still breaking is "[testPathAuto]: Node accessible through alias at [[...]/sites/all/modules/pathauto/tests/pathauto.test line 84]", which tries to fetch the node using the alias.

Freso’s picture

And even reverting the originally committed patch from this issue doesn't take the fail away.

greggles’s picture

Status: Reviewed & tested by the community » Fixed

And fixed - http://drupal.org/cvs?commit=131753

Thanks for the reviews/testing.

Anonymous’s picture

Status: Fixed » Closed (fixed)

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

loze’s picture

I know this is a year old, but did this ever make it into the official release?
I cant seem to get this functionality to work. my url titles are being cut off in mid word.
Is there an option to enable this that im missing?

thanks.

theshanergy’s picture

There is a similar issue at the beginning of an url - if you have a page who's title starts with a short word (ie. 'to') it will remove it, but leave the separator. Creating a node titled 'To Something' creates an url of '/-something', instead of just '/something'.

greggles’s picture

@msiama - is that problem still present in Pathauto or did this patch fix it (this patch is in the tip of 6.x-2.x dev and in 6.x-1.2

interestingaftermath’s picture

Version: 7.x-1.x-dev » 6.x-1.4
Status: Closed (fixed) » Active

I hate to be a pain but I am experiencing this issue with the 6.x-1.4 release.

This: Broker Commissions Will Get Squeezed by Health Reform, but a New 'Navigator' Role Is Seen Growing

translates to this: ...enews/archive/2010/07/07/Broker-Commissions-Will-Get-Squeezed-Health-Reform-New-Navigator-Role-Seen-

I didn't think I should have to mess with the patch since it's from like 2 years ago. What am I doing wrong?

dave reid’s picture

Status: Active » Fixed

@interestingaftermath: Can you please file a new issue detailing exactly what's going wrong for you instead of opening tickets that have been closed for several months or years?

interestingaftermath’s picture

Dave, this is the second post you've made that comment on but I really don't understand your reasoning... The issue is DIRECTLY related to this one (as was the other issue). I will open a new issue as requested but it really seems pointless and unorganized. People can read timestamps, that's what they're for.

Status: Fixed » Closed (fixed)

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