Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Any spaces in a URL cause link_validate_url() to return FALSE, and generate a "Not a valid URL" error.
I fixed it in mine, quick and dirty, by adding this line at 686 in link.module.
$text = str_replace(' ','%20',$text);
Seems to work OK for me.
Comment | File | Size | Author |
---|---|---|---|
#2 | 575344_convert_spaces.patch | 1.13 KB | jeffschuler |
Comments
Comment #1
jcfiala CreditAttribution: jcfiala commentedHmmm. That sounds like a decent thing to do. I'll try to fit it in there.
Of course, if you can roll a patch of that change, that would be a nice thing to share back to the project, and make it easier to include! Give it a try!
Comment #2
jeffschulerI ran into this problem too.
I'm not sure where line 686 was when you first posted, Ogredude, but, since you use
$text
, I'd guess it's inlink_validate_url()
.The attached patch works for my test case of a normal URL with some spaces in it.
I think, though, that the
str_replace()
probably belongs elsewhere in the function, (if not in another function entirely.) It should probably only apply to$external_pattern
links, right? And then only in$end
...Well, here's for starters.
Comment #3
jcfiala CreditAttribution: jcfiala commentedOkay, I've fixed this by changing the query regex to accept spaces in that section. I don't think spaces are valid in any other part of the url, and really the query is pushing it.
Comment #4
calebtr CreditAttribution: calebtr commentedThis problem goes beyond the space character. People put things in URLs that they shouldn't, then users copy and paste them into Drupal forms, and there is a whole set of characters where they are okay if encoded but not if left blank.
Would it be better to urlencode() the link before validation/display instead of expanding the regular expression?
For example, I have a problem with { and }. Someone puts these in URLs even though they should use %7B and %7D instead, which are valid. I had submitted the validation-circumvention patch at http://drupal.org/node/323879 but agree that I don't want any old person putting any old text in a link field.
Is there any interest in a patch that did this?
Comment #6
samhassell CreditAttribution: samhassell commentedThe problem here is not in the specifics of what is a legal URL as in the RFCs. The issue is that general users will copy a link out of their browser address bar, which copies it without url encoding. They then paste it into the link field which throws a validation error due to the spaces.
Here's the URL I am looking at:
http://www.fifa.asn.au/files/pdf/publications/Cracking the Nutrient Code optimized.pdf#page=35
I think its a valid use case as it's not fair to expect general users to understand url escaping.
For now I'm applying jeff's patch in #2. All those regex's are a bit scary for me :)
Cheers,
Sam.
Comment #7
dqdDear followers of this issue: please read the project page info of link module for further validation issues. There is already an issue to collect and discuss all possible validation scenarios in general. That's why I will mark this one here as duplicate. I need all concentration inside the ONE and only discussion to move forward. After a D7 implementation we will provide a D6 backport.
Explanation: There are too many corner cases and validation wishes of users to implement them all serially one after the other. We would have a 40 lines cluttered settings form for validation methods, conflicting with each other randomly. I think, the right way is to find a maybe more complex but all embracing new configuration method, which lets the admin better decide, how and when to validate the url. Including a good description which helps to set it up. This will surely lead to a new branch
Comment #8
TechNikh CreditAttribution: TechNikh commentedWhen I use "%20" in the url it's rendered as "%2520"
so I am unable to use a link with space in URL
Comment #9
dqdYes, the space is usually encoded to "%20" though. Any parameters that pass to a URL should be encoded, simply for safety reasons. URLs are defined in RFC 3986, though other RFCs are relevant as well but RFC 1738 is obsolete.
URLs: They may not have spaces in them, along with many other characters. Since those forbidden characters often need to be represented somehow, there is a scheme for encoding them into a URL by translating them to their ASCII hexadecimal equivalent with a "%" prefix.
Most programming languages/platforms provide functions for encoding and decoding URLs, though they may not properly adhere to the RFC standards. For example, I know that PHP does not.
For further discussion please read comment #7 carefully. thanks.
Comment #10
dqd#1318938: An all-embracing attempt for URL validation and Input / Output Form Filtering