In a project I'm working on we have a client pasting URL encoded links in the link field. The URL's get encoded again for display, which result in broken links. Is it possible to URL decode the string before saving in _link_process() or something?

Normal links won't be affected, and URL encoded links will be fixed. Possible you could make the URL decode optional by configuration so the impact is very low. Could be that I'm missing something, but it seems to be a small change?

Comments

saitanay’s picture

Issue summary: View changes
StatusFileSize
new667 bytes

Had the same issue.

A url link
http://example.com/uri?target=XXX:NOTICE:XX7809583:EN:HTML
was being rendered as
http://example.com/uri?target=XXX%3ANOTICE%3XX7809583%3AEN%3AHTML

The module uses core's url() to generate the link which seems to mandatorily encode all qureystrings (the parts of the url after =)

Attached is a patch that works around by decoding the urls back before rendering them.

amitgoyal’s picture

Status: Active » Needs work

Minor issues,

- There is extra space at each of the line added in the patch.
- Space is needed after '//'.

saitanay’s picture

StatusFileSize
new613 bytes
saitanay’s picture

StatusFileSize
new653 bytes
Staxewing’s picture

Hi, patch doesn't fix my problem with urls that contains colons. In a very practical way I found that if I reset the array $url_parts['url'] in _link_parse_url() function I solved the problem:

NO$url_parts['url'] = $url;
OK$url_parts['url'] = "";

Until now I had no further problem.

achap’s picture

I had a similar problem. We were adding files and then copying the URL to a link field in a content type. The problem is that the link gets encoded twice so % gets converted into 25. E.g. %20 becomes %2520

The patch fixes the link destination, so the href goes back to having %20, however the title of the link (If you haven't specified one explicitly) still has broken encoding of %2520. However this doesn't affect the functionality of the link.

E.g. the href of sites.com/file%2520new.pdf becomes sites.com/files%20new.pdf but the title remains as sites.com/file%2520new.pdf

charles belov’s picture

Workaround for the %25 issue is to go to /admin/config/content/formats/plain_text and check Convert URLs into links. Downside is that if you don't want people entering URLs into plain text fields because they provide a sub-optimal experience/bad SEO, tough luck.