If you aren't logged in, and view a page where comments would be allowed if you were logged in, there's a line at the bottom of the page that says "Login or register to post comments". "Login" and "register" are both links, and the URLs for both are broken. They're supposed to take you to the correct page to login or register, passing an argument to that page so that it will send you back to the "comment-form" section of the current page after you successfully login or register.
If the current page is, for example, "http://www.example.com/node/30", then the "Login" link should be "http://www.example.com/user/login?destination=comment/reply/30#comment-form" and the "register" link should be "http://www.example.com/user/register?destination=comment/reply/30#commen...".
However, instead, the "Login" link is "http://www.example.com/user/login?destination=comment/reply/30%2523comme..." and the "register" link is "http://www.example.com/user/register?destination=comment/reply/30%2523co..."
Apparently what's happening is the "#comment-form" section of the URL is first being translated (incorrectly) to "%23comment-form", which is then in turn being translated to "%2523comment-form" ("#" is ASCII 23, and "%" is ASCII 25).
I have attached a patch which solves this problem, though I'm not familiar enough with Drupal internals to speculate about whether or not it might cause other problems.
| Comment | File | Size | Author |
|---|---|---|---|
| comment.module.diff | 865 bytes | BrentChapman |
Comments
Comment #1
Bodo Maass commentedApparently, this bug has been around since 4.7 and has been fixed but never committed. Here is a duplicate report with a patch for 5.x-dev: http://drupal.org/node/93427
Comment #2
damien tournoud commentedThere is no bug here.
The URL is supposed to be in the form
http://www.example.com/user/login?destination=comment/reply/30%23comment-formbecause the anchor part#comment-formis part of thedestination=parameter, not of the parent URL. But because of some Apache mod_rewrite quirks, drupal_urlencode() double-escape some characters (see the documentation for this function for the rationale for this), that's why you are seing this%2525.Comment #3
Bodo Maass commentedHi Damien,
If this is not a bug, could you point me in the right direction for some other way to fix this? Without the patch, my site isn't working, so I need to change something. If comment.module is not the right place, what should I do?
I understand it has to do with mod_rewrite and drupal_urlencode. But is there an existing fix for this problem somewhere?
Comment #4
Bodo Maass commentedOk, I start to understand more. The double-encoding of the hash sign does indeed cause no problems on a clean new test site and does not seem to be a bug.
My problem is that I see broken links of the form '/user/register?destination=comment/reply/291%252523comment-form', where the hash sign is somehow triple-encoded, and I kept seeing unsuccessful attempts to leave comments in my log file.
I came to this bug report here because I just thought the comment register links are broken, but the issue seems more subtle, and perhaps specific to my site.
Comment #5
Bodo Maass commentedIt was indeed a problem with my rewrite rules. Fixed by adding [NE] to the problematic rule to prevent mod_rewrite from re-encoding the already encoded url and thereby changing %2523 into %252523.
I'm not sure if this is the right way to fix this, but it seems to work so far.
Comment #6
phreadom commentedCould you give me some more specific information on the fix?
I'm trying to figure this out myself and am feeling a little over my head.
For instance, are we supposed to be making the mod_rewrite rule changes in the .htaccess in the web root, and to which rule(s) specifically?
I've read the mod_rewrite documentation on Apache.org to understand what the [NE] is supposed to be doing, but I'm now trying to figure out where exactly I need to apply it (correctly).
Thank you in advance.
Comment #7
Bodo Maass commentedHi phreadom,
My problem was due to a redirection from http to https. I don't know if this is the same thing you are seeing. My fix was applied to the .htaccess file in the root of the drupal folder by changing this line:
into this: