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.

Comments

jeffam’s picture

Status: Active » Needs review
StatusFileSize
new1.35 KB

This 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.

chrisarusso’s picture

This "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;amp;-part2

chrisarusso’s picture

Attached patch that applies cleanly to 7.x-1.x-dev and 7.x-1.1

jackalope’s picture

Had the same problem; the patch posted in #3 is working well so far. Thanks illmasterc!

jcfiala’s picture

Issue summary: View changes
Status: Needs review » Fixed

Okay, 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.

Status: Fixed » Closed (fixed)

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

jkingsnorth’s picture