Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kkaefer’s picture

Explanation: If your form action is something like foo?bar=baz, the query parameters will be stripped when submitting that form.

chx’s picture

FileSize
673 bytes

You must either specify a description or change something about this issue.

Dries’s picture

How does a base URL prevent encoding? Because of the handling in url()?

chx’s picture

Yes. It becomes an absolute URL and external URLs are returned early, before

    $path = drupal_get_path_alias($path);
    $path = drupal_urlencode($path);
Dries’s picture

One important difference might be the fact that url() escape its parameters whereas request_uri() returns data that is potentially insecure (XSS). As you were recently investigating drupal_goto() you might be able to comment on that before we go ahead and commit this patch?

JirkaRybka’s picture

Just cross-linking a related isuue (bug report on D6 install.php) - http://drupal.org/node/172262
Not sure if that one is caused by this entirely / partially / not at all (the patch above doesn't help), but still seems related.

JirkaRybka’s picture

My problem with Install (linked above) turned out to be completely unrelated, so you can ignore my commnets here.

drumm’s picture

Status: Reviewed & tested by the community » Needs work

Site in subdirectory, clean urls off, redirects add duplicate copies of the subdirectory.

jamix’s picture

I've faced the same problem with Drupal 5 not keeping table's sort parameters upon form submit. I used the workaround below to fix this behavior; works beautifully.

function mymodule_sample_form() {  
  // Keep the original URL in order to preserve table sorting
  global $base_url;
  $form['#redirect'] = $base_url . request_uri();
  
  ...
  
  return $form;
}
TR’s picture

Version: 5.x-dev » 6.x-dev

According to #2 this is apparently an issue in Drupal 6.x. I don't know whether it's still a problem in D7 or D8. Changing version because Drupal 5.x is no longer supported.

rszrama’s picture

Version: 6.x-dev » 8.x-dev
Priority: Critical » Major

This issue still exists; just found it through a bug report in Commerce. I don't think this needs to be critical, so I'm just moving it to major since we didn't have the priority when this issue was first reported. I'm guessing this needs a re-roll...

dawehner’s picture

Issue tags: +Needs tests

This definitive needs simpletests, but sadly there are no extra tests for form redirection.
Here is another issue for it #1261842: Create test for form redirect

catch’s picture

Issue tags: +Needs backport to D7

Tagging.

NROTC_Webmaster’s picture

Here are the patches for D7 and D8.

tim.plunkett’s picture

Merging in the tests from #1261842: Create test for form redirect.

tim.plunkett’s picture

Status: Needs review » Needs work

This must be something to do with the base URL, I tried a couple tests locally (without a subdomain, unlike the bot) and they passed.

Something to look into tomorrow.

tim.plunkett’s picture

Status: Needs work » Needs review
FileSize
5.38 KB

Let's see some more info.

tim.plunkett’s picture

FileSize
5.57 KB

Debug code didn't take into account the absolute => TRUE in assertURL.

tim.plunkett’s picture

FileSize
5.49 KB

Ah, so it's the subdirectories? Later I'll figure out how to install Drupal locally with subdirectories, for now here's this.

tim.plunkett’s picture

Status: Needs review » Needs work

If you look at the debug messages for Drupal\system\Tests\Form\RedirectTest in that last patch, the base URL is 'http://drupaltestbot654-mysql/checkout', but the results of request_uri() are '/checkout/form-test/redirect?foo=bar', and checkout is duplicated.

But is that really the expected result of request_uri()? I would have thought it would be '/form-test/redirect?foo=bar'

tim.plunkett’s picture

Status: Needs work » Needs review
FileSize
5.33 KB

Hm, wonder how this might work.

Status: Needs review » Needs work
Issue tags: -Needs backport to D7

The last submitted patch, drupal-171267-28.patch, failed testing.

tim.plunkett’s picture

Status: Needs work » Needs review
Issue tags: +Needs backport to D7

#28: drupal-171267-28.patch queued for re-testing.

tim.plunkett’s picture

FileSize
5.31 KB

Here's a more straightforward patch.

For D7, we'll have to use a copy of $_GET, and unset 'q' first.

chx’s picture

Assigned: tim.plunkett » Crell

I can't RTBC this -- although I would normally. I would like to see what Crell says about the usage of request.

tim.plunkett’s picture

While attempting a backport to D7, I realized that there was no need for any of the content type stuff in the setUp(), I must have just copy/pasted that.
This just removes those, no other changes.

In the D7 one I didn't even bother removing 'q' from $_GET first, since url() ignores it anyway.

Crell’s picture

For the D8 patch, this could only be a temporarily solution since:

1) request() is a temporary BC shiv that I hope we can remove.

2) drupal_goto() is going to have to change anyway, as you should now be using a RedirectResponse object.

Of course, we have some Drupal-specific logic in drupal_goto(), which I don't know that we can entirely eliminate. (destination= handling, etc.) That makes me wonder if we need a DrupalRedirectResponse object of some sort, (or probably a Drupal-namespaced RedirectResponse) that replicates the handling from drupal_goto(). GET query parameter persistence should be part of that, where appropriate, but I also worry about that class ending up with hard dependencies in it if we're not careful.

So, tentatively OK with this patch for now, on condition that we spin up a new issue to discuss how to eliminate drupal_goto() entirely in favor of something cleaner that would internalize the solution to this problem.

tim.plunkett’s picture

chx’s picture

Status: Needs review » Reviewed & tested by the community

OK then temporarily let's get this major fixed :)

catch’s picture

Version: 8.x-dev » 7.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

Thanks for opening the follow-up. This looks great as an interim fix and something that should be more or less straightforward to backport. Committed/pushed to 8.x.

tim.plunkett’s picture

Assigned: Crell » tim.plunkett
Status: Patch (to be ported) » Needs review
FileSize
4.96 KB
4.61 KB

Thanks! Rerolled.

chx’s picture

Status: Needs review » Reviewed & tested by the community

Yay! Didn't even take five years to get this superb complicated issue fixed.

andypost’s picture

+1 to commit

David_Rothstein’s picture

Status: Reviewed & tested by the community » Needs work
+    drupal_goto(current_path(), array('query' => $_GET));

This needs to use drupal_get_query_parameters(). Otherwise, visiting the form at, e.g., admin/config/system/site-information will redirect you to a URL that looks like admin/config/system/site-information?q=admin/config/system/site-information.

That bug won't exist in Drupal 8, but I would think it should use drupal_get_query_parameters() there too anyway, for consistency with the rest of the codebase. Leaving at D7 for now, though.

dcam’s picture

Status: Needs work » Needs review
FileSize
4.98 KB

I got the same result as #41. When submitting the form at admin/config/system/site-information I was redirected to admin/config/system/site-information?q=admin/config/system/site-information. I'm attaching a patch that replaces $_GET with drupal_get_query_parameters(). It did seem to solve that particular issue.

tim.plunkett’s picture

Assigned: tim.plunkett » Unassigned
Status: Needs review » Reviewed & tested by the community

Good catch David.

It seems that in D8, drupal_get_query_parameters() hasn't been updated to use the kernel, and I'd be just as happy to leave it as is there.

This is RTBC for D7.

webchick’s picture

Assigned: Unassigned » David_Rothstein

Going to kick back to David since he seems to understand this code better than I do. :)

David_Rothstein’s picture

Version: 7.x-dev » 6.x-dev
Assigned: David_Rothstein » Unassigned
Status: Reviewed & tested by the community » Patch (to be ported)
Issue tags: +Needs backport to D6

Committed to 7.x - thanks! http://drupalcode.org/project/drupal.git/commit/50fce51

Moving to Drupal 6 for backport.

rszrama’s picture

Woohoo! Happy day. : )

dcam’s picture

Status: Patch (to be ported) » Needs review
FileSize
690 bytes

This is a reroll of #2 for D6.

Status: Needs review » Needs work

The last submitted patch, drupal-171267-47.patch, failed testing.

rszrama’s picture

Should be request_uri() not request_url(), but shouldn't it also backport your tests?

dcam’s picture

Status: Needs review » Needs work
FileSize
690 bytes

Thanks for catching the request_uri() problem.

As for the tests, I'll admit I'm still a core newb and this is my first 6.x patch, but I thought tests don't get backported because simpletest isn't in core. If I'm mistaken then someone please correct me.

dcam’s picture

Status: Needs work » Needs review
xjm’s picture

Status: Needs work » Needs review
Issue tags: +Needs manual testing

Thanks @dcam! You're correct about the tests. Since this is now a D6 patch, it needs to be tested by hand.

David_Rothstein’s picture

Be careful backporting this to Drupal 6 - it looks like it probably caused some issues: #1836082: Drupal 7.17 breaks some form redirects (including views exposed filters)

Status: Needs review » Closed (outdated)

Automatically closed because Drupal 6 is no longer supported. If the issue verifiably applies to later versions, please reopen with details and update the version.