Looks like this issue was previously addressed: #1688420: Links module adds amp; to url
However, I still see the issue. With version 7.x-1.1 and a URL like this: sites/default/files/Mouse&my.jpg, Link produces this: http://test.dev/sites/default/files/Mouse%26amp%3Bmy.jpg
Patch to follow.
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | remove-check-plain-on-url-display-1936784-3.patch | 683 bytes | chrisarusso |
| #1 | link-amp-text-in-relative-URLs-1936784-1.patch | 1.35 KB | jeffam |
Comments
Comment #1
jeffamThis patch removes the check_plain() call to the base part of the URL. check_plain() is just a wrapper around the php htmlspecialchars() function. That, in turn, does the following:
'&' (ampersand) becomes '&'
'"' (double quote) becomes '"' when ENT_NOQUOTES is not set.
"'" (single quote) becomes ''' (or ') only when ENT_QUOTES is set.
'<' (less than) becomes '<'
'>' (greater than) becomes '>'
Non of these things are appropriate in a URL, and Drupal's url() function already does a fine job of escaping URLs as needed.
Comment #2
chrisarusso commentedThis "works" by simply removing the check_plain of course. However, there must be a more elegant way to run a character check but not break ampersand URLs.
For the record, I have a URL http://example.com/part1-&-part which link output as
http://example.com/part1-&amp;-part2Comment #3
chrisarusso commentedAttached patch that applies cleanly to 7.x-1.x-dev and 7.x-1.1
Comment #4
jackalope commentedHad the same problem; the patch posted in #3 is working well so far. Thanks illmasterc!
Comment #5
jcfiala commentedOkay, good point. I've dug through the code, and as best as I can see, that check_plain isn't needed - if the url is displayed as a title, it goes through check_plain again later _anyway_ at the display layer. I have, as suggested, yanked it out.
Comment #7
jkingsnorth commentedMarked #1885062: ampersand '&' in URL is replaced with '&' as a duplicate.