The function url() don't escape HTML so you need to add check_url() or drupal_urlencode() to do this. This code will generate links with "&" instead of "&".
if (variable_get('user_register', 1)) {
return t('<a href="/%login">login</a> or <a href="/%register">register</a> to post comments', array('%login' =>url('user/login', $destination, 'comment-form'), '%register' => url('user/register', $destination, 'comment-form')));
}
else {
return t('<a href="/%login">login</a> to post comments', array('%login' =>url('user/login', $destination, 'comment-form')));
}
The handbook page "How to handle text in a secure fashion" http://drupal.org/node/28984 has good info on this. It suggest check_url() for user contributed links and drupal_urlencode() for other links.
My patch applies drupal_urlencode() since it's internal links only.
Comments
Comment #1
frjo commentedComment #2
acp commentedJust found this error while validating some pages. Could you please apply the patch ?
I know it's not much, but would be great to have full compliance with w3c standards :).
Comment #3
Steven commentedPatch is bogus, you are misunderstanding the guidelines. Check_url() is necessary.
Comment #4
acp commentedIndeed it seems so, here's the corrected version of the patch...
Comment #5
Gman commentedIt seems that the drupal_urlencode has gotten into the core, since drupal.com is not working in this respect, and neither is my site.
If you try to login while responding to a comment or forum post ("login or register to comment"), then the URL looks like this:
http://drupal.org/user/login?destination=comment/reply/77562%2523comment...
Which leads to this after you login, which is a failure, no page found:
http://drupal.org/comment/reply/77562%2523comment_form
With the check_url I get:
http://drupal.org/user/login?destination=comment/reply/77880#comment_form
Which leads to
http://drupal.org/comment/reply/77247
Which drops the # anchor altogether. At least it is not a blank page though. Definitely needs to be fixed since this is breaks the login sequence.
Comment #6
mhutch commentedI can repro this too.
(Also subscribing to issue, as it's been discouraging my users from commenting!).
Comment #7
toemaz commentedI encouter the same bug with 4.7.4.
When submitting this follow up, I had to choose a version (x.y.z. is not a valid version), so I've selected 4.7.x-dev. Hope that this is ok.
Comment #8
toemaz commentedYou can find the solution over here:
http://drupal.org/node/78515#comment-133103