A contributor on one of my sites just discovered what seems a bug. Here is how to reproduce it:

  1. work on a drupal site, say http://www.drupal.org/
  2. create a post, say a story
  3. prior to submitting, define the "URL path settings" : do not read the description that says these must be local, and type in some absolute URL, like http//:www.example.com/.
  4. submit

At this point, you find yourself on http://www.drupal.org/http%3A//www.example.com, which causes a "page not found" error.

This seems to be a bug: absolute paths should probably cause a post validation error. Just because users can't read doesn't mean sites shouldn't give some clues instead of bailing out.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

fgm’s picture

A possible solution would be to sanitize aliases so that incorrect urls like absolute ones are converted to something that will actually be recognizable when requested and point to the same page.

ChrisKennedy’s picture

Title: Absolute path not avoided » Disallow absolute urls as path aliases

Agreed that this should be fixed; I had it happen to me once or twice when I just started using drupal.

Darrell’s picture

In ver 4.6 I was using absolute urls as path aliases for some static html pages. When I upgraded to 4.7.4 that no longer worked but there was no help given to fix it.
What I found that worked for me is this.
Drupal resides in http:www.mysite.com/drupal. The static page resides at http://www.mysite.com.
The old absolute url path was http://mysite.com/index.html
The new url path that works is ../index.html

ChrisKennedy’s picture

Status: Active » Needs review

Rather than return an error, this patch silently removes any leading or trailing forward slashes. I think this is the best solution in terms of usability. Without this patch it can be troublesome to fix nodes given an incorrect alias, because the links to the aliased url will be broken too.

I tested with http://www.example.com and it worked fine on FF and IE without any patch, so I didn't include a fix for that input.

ChrisKennedy’s picture

FileSize
749 bytes

Dang, forgot to attach the patch again.

Darrell’s picture

So am I being told that there is no way to do an absolute URL to another site?
I tried putting a link to another site of mine using fill HTML and it was converted to a local link.
What is going on?????

Darrell’s picture

Forgot to say I am using 4.7.4.
At this rate, every time I upgrade to the latest version I loose at least one thing that I need. My last upgrade I lost the album module. This time I lost absolute URLs, authenticated user and all of the usable info under the status column in the users list.
I am beginning to think that upgrading is not a good idea.

fgm’s picture

Darrell, this is not what is at point here: the problem being discussed is that you should not create a page on site A and set for it an alias residing on site B, since site B would normally have no way to redirect you to the original page on site A.

This has nothing to do with links in post content.

drumm’s picture

Version: 5.0-beta2 » 6.x-dev
keith.smith’s picture

Status: Needs review » Needs work

patch no longer applies

# patch -p0 < path_absolute.patch
patching file modules/path/path.module
Hunk #1 FAILED at 128.
1 out of 1 hunk FAILED -- saving rejects to file modules/path/path.module.rej

Jody Lynn’s picture

Status: Needs work » Needs review
FileSize
2.28 KB

New patch for HEAD. This patch trims leading or trailing forward slashes, and removes the warning from the field description. It seems that absolute paths no longer break anything anyway.

moshe weitzman’s picture

looks good. i have not tested.

alasda’s picture

Status: Needs review » Reviewed & tested by the community

Verified issue
Changed url to /my/page/
Upon viewing, was directed to my/page
Editing the page also shows corrected my/page URL
Warning message did not appear in URL setting directions

Ready for commit

Gábor Hojtsy’s picture

Status: Reviewed & tested by the community » Needs review

Erm, what happens to http://www.example.com/ when trim-ed with /? IMHO http://example.com Better? How does this solve the issue?

Jody Lynn’s picture

Title: Disallow absolute urls as path aliases » Remove leading and trailing slashes in path aliases
Status: Needs review » Reviewed & tested by the community

I might misunderstand your question but I think maybe the confusion is that the issue has morphed and is now mistitled.

The original issue was about absolute urls, but in head that issue is already fixed and no longer breaks anything. So actually this patch is to fix relative aliases that are misentered, like if someone enters a path /node/14, so that it will just fix it rather than having to include fineprint to warn you not to do it.

Gábor Hojtsy’s picture

Status: Reviewed & tested by the community » Needs review

Ah, good titles matter a lot. So what about adding a comment to that effect to the trim(). I remember we were puzzled on some parts of this function before, so it is always good to have this documented. I'd add something along the lines of

// Remove possible slashes from both ends to avoid invalid aliases.

ChrisKennedy’s picture

Yep, I had a comment in my original patch...

Gábor Hojtsy’s picture

Status: Needs review » Reviewed & tested by the community

I'll get to massaging this a bit later, but it looks good (although it changes a string, it fixes a quite often encountered usability issue).

Pancho’s picture

If we anyway have to change the string, we should put improve on the wording:

In path_admin_form():

  • "Specify an alternative path by which this data can be accessed." sounds too technical. Instead of "data", we could actually use "page", which would IMHO still be correct and a lot more specific and understandable.
  • "For example, type "about" when writing an about page." is misleading here: the about page must already be written, when being aliased here! We could either say "when aliasing an about page" or "to refer to an about page".

In both occurrences:

  • I would reorder the sentences and move the example to the end. The quotes might also be misleading, maybe <kbd>about</kbd> is better... (Looks like about then)?
  • On the admin page we use the term "path", in nodeapi we use "URL". We should stick with one.

Proposal:
"Specify a path alias by which this page can be accessed. Use a relative path. For example, type <kbd>about</kbd> to refer to an about page."

and

"Optionally specify a path alias by which this node can be accessed. Use a relative path. For example, type <kbd>about</kbd> when writing an about page."

Also it is very misleading that the module is called "Path" (path.module) and the admin page on the other hand "URL aliases". I always intuitively search for a "path" menu entry, then scroll the list down and once I find "URL aliases", I remember: "Ahh, that was the misworded one".

Gábor Hojtsy’s picture

Status: Reviewed & tested by the community » Needs review

Back to discussion then.

Pancho’s picture

Some comments would be great, since we are mostly done!
All that's left is the correct naming conventions and the wording of two strings (see #19).

So let's start with the most general issue:
The module's name is "path". Right now, the functionality of path aliasing is inconsistently named "URL alias" (mostly), "Path alias", "alternative path".
While core shouldn't generally follow contrib - the important pathauto module is not called URLauto, but pathauto and it consistently uses the terminology "path alias".
Now I think we should make up a decision whether in the functionality be consistently called "Path alias" or "URL alias" in core... some opinions on this, please!

Jody Lynn’s picture

FileSize
2.28 KB

I made a new patch with Pancho's text changes. I agree with his points about the text.

Pancho’s picture

+1 for #22, though this only covers part of the naming issues.

Mainly I was criticizing the inconsistant usage of "URL alias" vs. "Path alias". We would need to unify this to "Path alias" IMO. The enclosed patch covers this. Unfortunately we'd need to rename two permissions, change four more strings and remove one. While this might sound inacceptable, this would IMHO be a large UI improvement and finally streamline the inconsistant naming.

Don't know if we should split that off this issue here, as we moved away from the starting point.
As the trim-slash part we all agree upon should be committed asap, this shouldn't hold back the patch in #22 anyway.

Jody Lynn’s picture

Version: 6.x-dev » 7.x-dev
Robin Monks’s picture

Status: Needs review » Needs work

No longer applies to HEAD:

patching file modules/path/path.module
Hunk #1 FAILED at 21.
Hunk #2 FAILED at 37.
Hunk #3 succeeded at 60 with fuzz 2 (offset -4 lines).
Hunk #4 succeeded at 84 (offset -1 lines).
Hunk #5 succeeded at 119 (offset -4 lines).
Hunk #6 FAILED at 126.
Hunk #7 succeeded at 183 (offset 2 lines).
Hunk #8 succeeded at 186 (offset -4 lines).
Hunk #9 FAILED at 201.
4 out of 9 hunks FAILED -- saving rejects to file modules/path/path.module.rej
patching file modules/path/path.admin.inc
Hunk #2 succeeded at 53 (offset 2 lines).
Hunk #4 succeeded at 80 (offset 2 lines).
Hunk #6 succeeded at 126 (offset 2 lines).
Hunk #8 succeeded at 158 (offset 2 lines).
Hunk #10 succeeded at 182 (offset 2 lines).

This is also a large patch that is hard to review, please consider splitting up this patch to make it easier to review quickly.

Robin

Jody Lynn’s picture

Agreed, Robin. The purpose of this patch is to remove leading and trailing slashes in user-entered paths, which is a usability improvement.

Pancho's naming consistency issue should be a separate issue.

The patch in #22 should be rerolled and retested for HEAD.

Jody Lynn’s picture

Status: Needs work » Needs review
FileSize
2.45 KB

Patch removes leading and trailing slashes in user-entered path aliases and adjusts path alias form description text to remove the no-trailing-slash requirement.

Status: Needs review » Needs work

The last submitted patch failed testing.

Jody Lynn’s picture

Status: Needs work » Needs review
FileSize
2.35 KB

I couldn't reproduce the test problem, resubmitting.

Status: Needs review » Needs work

The last submitted patch failed testing.

Bojhan’s picture

Issue tags: +Usability

tagging, failing test

Dave Reid’s picture

Marked #250525: Disallow trailing slashes in path aliases as a duplicate of this issue.

Jody Lynn’s picture

Status: Needs work » Needs review
FileSize
2.4 KB

reroll

rsaddington’s picture

Just reviewing this - if you enter an alias with a . after the / you get the same page not found issue.

Try with alias "http://example.com/."

rsaddington’s picture

FileSize
2.49 KB

Updated patch to fix dot issue noted in #34

Status: Needs review » Needs work

The last submitted patch failed testing.

rsaddington’s picture

FileSize
2.08 KB

Resubmitting for testing, incorporates changes made in #33

Jody Lynn’s picture

Removing all dots is a bad idea, for example a person might want to use an alias of test.html to match old paths. Seems better to use trim to remove dots from the beginning and end.

rsaddington’s picture

Title: Remove leading and trailing slashes in path aliases » Remove leading and trailing slashes in path aliases (and removing dots)
Status: Needs work » Needs review
FileSize
2.17 KB

Agree - patch modified to trim dots from either end.

Also removes "./" and "/." from aliases which cause page not found errors.

Status: Needs review » Needs work

The last submitted patch failed testing.

rsaddington’s picture

Status: Needs work » Needs review
FileSize
2.15 KB

re-rolling for another test...

chx’s picture

Status: Needs review » Needs work

The description changes and trimming the slash is great. However, str_replace is not, what if you have something like foo/bar/../baz then you can't just str_replace those pieces out , you need a validation error instead. Also, needs a test.

nirbhasa’s picture

If we took out the 2 str_replace lines in the patch and just submit the trim slashes functionality, would this then be able to get into D7?

Xano’s picture

Assigned: Unassigned » Xano

We had some discussion on this in IRC and I'll finish this tonight. I'll merge this issue with #394402: Path field needs better help text and validation.

drupal_was_my_past’s picture

Version: 7.x-dev » 8.x-dev
Status: Needs work » Needs review
Issue tags: +Needs backport to D7
FileSize
2.39 KB

Since #332333: Add a real API to path.module resolved the trim() and str_replace() issues by including trim() in all relevant cases. I believe what's left here is to the update the help text and to check in the alias validation for non-relative URLs. Patch attached to that effect.

Also tagging for backport to D7, though the string updates should probably be left out due to translation issues.

xjm’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests, +Novice

#46 looks good to me, and I agree with the point about a backport without the string changes. We'll also want to add some tests for this.

Note that the Drupal 8.x patch will need to be rerolled, because the core directory structure for Drupal 8 has now changed. (For more information, see #22336: Move all core Drupal files under a /core folder to improve usability and upgrades). When the patch has been rerolled, please set the issue back to "Needs Review."

Tagging as novice for the task of rerolling the Drupal 8.x patch.

Désiré’s picture

FileSize
2.43 KB

Here is the rerolled patch, for further work.

xjm’s picture

Status: Needs work » Needs review
Issue tags: -Novice

Thanks! Sending to testbot.

Désiré’s picture

Status: Needs review » Needs work

Still needs tests.

And the patch submitted in #46 and rerolled in #48 is not correct:
It check the alias is not an external url, and set an error if it is. But why? This issue is about trailing slashes. Why is it problem to set an external url for alias? It will works without this patch, I think it isn't a problem.

But the patch don't do anything with trailing slashes, and if we set an alias with them, Drupal will still give a page not found page.

drupal_was_my_past’s picture

Assigned: Xano » drupal_was_my_past
Status: Needs work » Needs review
FileSize
3.83 KB
2.38 KB

@Désiré you're right. I re-read the history of this issue and agree with you. Here is a test for leading and trailing slashes and a patch to fix leading and trailing slashes.

xjm’s picture

Thanks for the tests. Not sure about the new patch, though... What happened to validation errors for /. in the middle and the updated UI text, though? That's what the url_is_external() bit was for.

drupal_was_my_past’s picture

@xjm I'm feeling a bit confused about what the issue is and what the solution should be for it. It seems like external URLs are handled ok by the system, so I didn't address that in the patch. Should this issue be about removing leading and trailing slashes and dots or about external URLs?

xjm’s picture

Hmmm, I don't think external URLs "work." You end up with URLs like:
http://localhost:8888/d7/http%3A//localhost%3A8888/d7/foo

And it is related. E.g., for especial fun, create a node with this path alias if your site's domain is mysite.com:
http://mysite.com/foo/../

A user might enter an exernal URL for the same reason he or she might enter a relative path using . or .., and I think it makes sense to fail validation on that.

Maybe we just need to expand the scope of this issue?

In any case, the current patch above also does not fix other patterns that result in a 404, like:
/d7/foo/../bar
/d7/foo/./bar
...and I think these at least were in the original scope of the issue.

xjm’s picture

Status: Needs review » Needs work

Marking NW for the last case above, at least. We can strip leading or trailing slashes, sure, but I think we should be adding better validation on the field.

Bojhan’s picture

ran into this again at usability testing.

xjm’s picture

Tagging.

webchick’s picture

Wait. Why removing dots? "index.html" is a perfectly valid path alias. If the concern is that people put an entire URL in there, then prefix the field with the site address. (e.g. http://example.com/[_______________________])

But +1000 for stripping out leading/trailing slashes. That's just silly to do to people.

xjm’s picture

Not removing all dots... just path components with only dots and no alphanumeric characters. See #54. We need a more sophisticated regex.

jenlampton’s picture

Issue tags: +GoogleUX2012

updating tags

And here's a painful video showing the Google Usability study where someone entered a path with a leading slash and got an error.

drupal_was_my_past’s picture

Assigned: drupal_was_my_past » Unassigned
fago’s picture

Issue summary: View changes

I don't think disallowing trailing slashes is the right way - in some situations one might actually prefer them. Some SEOs consultants suggest adding trailing slashes to indicate a directory-like page.

So instead of removing it, I think it should work as via an URL alias - so that can be used to make the trailing slash variant the canonical path. However, I guess it would be a sane default behavior to disallow having two url aliases (with an without trailing slash) pointing at two different paths.

To make the paths work, something like that is enough. As said, better validation would make sense though.

/**
 * Implements hook_url_inbound_alter().
 *
 * @see drupal_get_normal_path()
 */
function module_url_inbound_alter(&$path, $original_path, $path_language) {
  // If no URL-alias has been found, try again with a trailing slash.
  if ($path == $original_path) {
    if ($source = drupal_lookup_path('source', $path . '/', $path_language)) {
      $path = $source;
    }
  }
}
Jody Lynn’s picture

The last submitted patch, 51: path-alias-with-test-103680-51.patch, failed testing.

TravisCarden’s picture

Title: Remove leading and trailing slashes in path aliases (and removing dots) » Path alias validation should test for full URLs

#1847174: Path alias validation should test for relative path, no trailing slash requirements addressed much of this. The only issue that remains seems to be failing validation for full URLs.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

quietone’s picture

Version: 8.9.x-dev » 7.x-dev
Issue tags: +Bug Smash Initiative

I tested this on a standard install of drupal 7.79-dev and Drupal 8.9.0 using the steps in the Issue Summary.

On Drupal 8.9.0 it is not possible to enter an alias that does not start with a '/'. A validation error, The alias path has to start with a slash. is displayed.

On Drupal 7 the alias is accepted and the problem is reproducible.

Therefor, moving to the Drupal 7 issue queue.