Posted by Kasper Souren on July 1, 2010 at 8:28pm
9 followers
| Project: | Link |
| Version: | 6.x-2.9 |
| Component: | Documentation |
| Category: | feature request |
| Priority: | minor |
| Assigned: | Unassigned |
| Status: | needs review |
Issue Summary
Currently local links (such as /node/1) are giving "Not a valid URL."
I was about to add a feature request to allow local links, when I figured this out. It would have saved me some time if the error message for this case would include e.g. "Don't start local links with /"
Comments
#1
Well, I suppose - but on the other hand, the system I'm using to validate urls doesn't know what kind of a url you were trying to make - it just knows that what you entered doesn't pass any of the regexes that define what's legal. It's a little silly saying "Don't start local links with /" in an error message if the user was trying to enter a non-local url.
#2
Is there a reason that URLs with a leading / are not accepted?
#3
It's standard throughout Drupal that /node/1 is not valid entered into a form field, where node/1 is.
I suspect it's related to how the url() function works.
#4
I encountered this issue and at first considered it a bug since "/node/1" is certainly a valid URL for a link target.
However, when the Link module renders/themes a URL, the URL gets run through url(), which translates a path like "node/1" to "/node/1" (if the Drupal base path is "/"). So I think it would help to note that when a relative URL is entered, it is relative to Drupal's base path.
This also means that if you're doing your own theming of a raw link field value, you should run the URL value through url().
#5
I would still consider this a bug. We have always trainer our users to consider urls that start with a slash to be relative to the root url, and urls that don't to be relative to the page they are on, since this is html standards. Just because drupal does things differently in the back end, doesn't mean we should expose our users to non html compliant standards. Its not a big issue, but I just wanted to say +1 for this addition.
#6
+1 I just encountered someone confused by this (them and myself included).
#7
Preceding / causing issue in Views when trying to use value from a link field formatted as URL, as plain text as the link path value of the Output this field as a link option in the Rewrite Results section of the field settings config.
#8
#9
Relative urls aren't working at all in some cases. If the link output is displayed on a page using an alias with a slash in it (for example content/mypage), then a link entered as node/1 will be directed to content/node/1.
#10
I'm not convinced this is important yet, and I'm setting it back to the 6.x, because there isn't a 7.x release yet.
Folks are, as always, welcome to provide patches for review.
#11
I suspect I'm running into this. I have a content type that contains an image field and a link field. I have a view with two fields. The first is the link field "as plain text", excluded from the display. The second is the image field "output field as a link" using the first field as the link URL. The resulting link is like "http://node/123" (drops the hostname.)
#12
OK. I see what's happening in the code, and it makes sense. The "URL, as plain text" runs the URL through
url()and returns that.For local paths (e.g.,
taxonomy/term/123), this will return/taxonomy/term/123.Sensible. Except.
When this is used in Views or as a token passed into a field that runs the token'd text through
url()again, we get//taxonomy/term/123(arguably a bug in url()).So, here is a patch that adds a new link view option: "URL, as entered." It runs the URL through
check_plain(), but noturl()orl(). This can be tokenized appropriately.