Comments

lilou’s picture

Status: Needs review » Needs work

Why call request_uri() instead of $_SERVER['REQUEST_URI'] ?

jgraham’s picture

Status: Needs work » Needs review

I think the documentation for request_uri says it all;

"Since $_SERVER['REQUEST_URI'] is only available on Apache, we generate an equivalent using other environment variables."

Status: Needs review » Needs work

The last submitted patch failed testing.

drupal_was_my_past’s picture

Version: 7.x-dev » 8.x-dev
Status: Needs work » Needs review
Issue tags: +Needs backport to D7
StatusFileSize
new585 bytes

Re-roll patch from #1.

xjm’s picture

Status: Needs review » Needs work
Issue tags: +Novice

Looks good to me. Does this function have unit tests? We could maybe test a few patterns with a dummy $_SERVER, I guess.

Note that the Drupal 8.x patch will need to be rerolled, because the core directory structure for Drupal 8 has now changed. (For more information, see #22336: Move all core Drupal files under a /core folder to improve usability and upgrades). When the patch has been rerolled, please set the issue back to "Needs Review."

Tagging as novice for the task of rerolling the Drupal 8.x patch.

balintd’s picture

Status: Needs work » Needs review
StatusFileSize
new610 bytes

Here is the rerolled patch.

denes.szabo’s picture

Here is the test for this issue.

Status: Needs review » Needs work

The last submitted patch, request_uri-226873-7.patch, failed testing.

denes.szabo’s picture

Status: Needs work » Needs review
StatusFileSize
new2.26 KB

Fixed test $_SERVER variables in setUp().

xjm’s picture

Awesome, thanks for the tests! There's a couple minor things with the code style that distracted me a bit:

+++ b/core/modules/simpletest/tests/common.testundefined
@@ -1827,6 +1827,57 @@ class DrupalRenderTestCase extends DrupalWebTestCase {
+ * Test for drupal_detect_baseurl().
...
+   * Test valid base urls.

Should begin "Tests." (Yeah, that's different from the rest of the file, but we're in the process of cleaning it up as a part of #1310084: [meta] API documentation cleanup sprint). ;)

+++ b/core/modules/simpletest/tests/common.testundefined
@@ -1827,6 +1827,57 @@ class DrupalRenderTestCase extends DrupalWebTestCase {
+ * @see http://drupal.org/node/226873
+ * "Since $_SERVER['REQUEST_URI'] is only available on Apache, we generate an
+ * equivalent using other environment variables."

I think we could probably leave off the @see here, since it can be gotten via git blame. Instead, let's remove the quotes and say:
Since $_SERVER['REQUEST_URI'] is only available on Apache, we use drupal_detect_baseurl() uses request_uri() to generate an equivalent using other environment variables.

+++ b/core/modules/simpletest/tests/common.testundefined
@@ -1827,6 +1827,57 @@ class DrupalRenderTestCase extends DrupalWebTestCase {
+      'name' => 'Valid Base Url',
+      'description' => "Performs tests on Drupal's valid base url function.",

Very minor point, but URL should be all in caps.

+++ b/core/modules/simpletest/tests/common.testundefined
@@ -1827,6 +1827,57 @@ class DrupalRenderTestCase extends DrupalWebTestCase {
+    // Save $_SERVER variable.

I'd clarify this a little: "Save original $_SERVER variable." Then, above the next section, add a comment that says something like: "Create a dummy $_SERVER variable for testing."

+++ b/core/modules/simpletest/tests/common.testundefined
@@ -1827,6 +1827,57 @@ class DrupalRenderTestCase extends DrupalWebTestCase {
+  ¶

Teensy bit of trailing whitespace here.

+++ b/core/modules/simpletest/tests/common.testundefined
@@ -1827,6 +1827,57 @@ class DrupalRenderTestCase extends DrupalWebTestCase {
+    $this->assertEqual($url, $request_uri, t('The base URL detecting is valid.'));

Maybe reword a little to "The detected base URL is valid." Also, we can probably leave off the t(). See #500866: [META] remove t() from assert message.

I'd aslo suggest an inline comment or two in testValidBaseUrl() to explain what we're doing.

If you roll a new patch, could you also re-upload the (new) test-only version just to make it clear that it fails for the "right" reason this time?

Great job on this. Thanks for picking up the issue so quickly. :)

Status: Needs review » Needs work

The last submitted patch, request_uri-226873-9.patch, failed testing.

xjm’s picture

Hmm, looks like there's still something else going on. I'll try it locally.

denes.szabo’s picture

Yeah, locally the test ran succesfully. After the first failed server test I tried to set up a test environment similar to real one.

David_Rothstein’s picture

Hate to say this given the work that's already gone into this issue, but for Drupal 8, at least, couldn't we just delete the drupal_detect_baseurl() function entirely? It doesn't seem to be used anywhere in core, and it's hard to see why it would be useful elsewhere since we have $GLOBALS['base_url'] instead...

For Drupal 7 backport I guess we have to keep it, but it might not be worth too much effort getting the tests to work if they're troublesome (if the function is on its way out anyway).

David_Rothstein’s picture

That said, I'm guessing the test fails due to this:

+    $_SERVER['SCRIPT_NAME'] = 'index.php';

That won't work if Drupal is being run in a subdirectory (such as http://localhost/drupal), and it failed for me when I tried it locally because of that... Maybe the testbot runs in a subdirectory also?

Meanwhile the "Undefined index: HTTPS" PHP notice in the tests seems to be a straight-up bug in drupal_detect_baseurl() itself. I'm not sure about the other PHP notices; perhaps they are also.

denes.szabo’s picture

I agree with you, I have just found one calling the drupal_detect_baseurl() and seem replaceable with $GLOBALS['base_url'].

Ulisse2’s picture

.

albert volkman’s picture

Status: Needs work » Needs review
StatusFileSize
new961 bytes

If there's no use for the function, this patch removes drupal_detect_baseurl().

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

The last submitted patch, request_uri-226873-18.patch, failed testing.

BrockBoland’s picture

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

#18: request_uri-226873-18.patch queued for re-testing.

kscheirer’s picture

Title: Patch install.inc to use request_uri() » With drupal_detect_baseurl(), D8: now unused - remove it, D7: make use of request_uri() and test
Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs change record

For the D7 backport, the patch in #9 needs work but it's a good place to start. #18 seems sane for D8. This counts as an API change in D8, so once this is committed we'll need a change notice as well. Docs on change records.

catch’s picture

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

Committed/pushed to 8.x, thanks!

catch’s picture

Version: 7.x-dev » 8.x-dev
Status: Patch (to be ported) » Needs work

Sorry, typed too fast, no longer applies.

longwave’s picture

Status: Needs work » Needs review
StatusFileSize
new965 bytes

Rerolled #18.

catch’s picture

Version: 8.x-dev » 7.x-dev
Status: Needs review » Patch (to be ported)

Thanks for the quick re-roll. Actually committed/pushed this time. Back to 7.x for backport.

petermallett’s picture

Issue summary: View changes

I made a port of the patch from #9 for 7.x including the suggested minor changes in #10, I'm assuming this will still fail, but maybe get this moving again.

petermallett’s picture

StatusFileSize
new2.21 KB
David_Rothstein’s picture

Status: Patch (to be ported) » Needs review

Status: Needs review » Needs work

The last submitted patch, 27: request_uri-226873-26.patch, failed testing.

petermallett’s picture

Looked at this a bit more this morning, it looks like this function just doesn't do what is intended. Also, it is never called anywhere that I can find in D7 either.

I could have sworn this test was passing for me yesterday, but looking today it is not & it's due to $_SERVER['SERVER_NAME'] not being set. I looked into how $base_url is created in drupal_settings_initialize(), and it is using $_SERVER['HTTP_HOST']; perhaps drupal_detect_baseurl has just been broken/unused for a long time & not noticed?

  • catch committed 1691c94 on 8.3.x
    Issue #226873 by Denes.Szabo, rocket_nova, balintd, Albert Volkman,...

  • catch committed 1691c94 on 8.3.x
    Issue #226873 by Denes.Szabo, rocket_nova, balintd, Albert Volkman,...
stefan.r’s picture

Issue tags: -Novice

  • catch committed 1691c94 on 8.4.x
    Issue #226873 by Denes.Szabo, rocket_nova, balintd, Albert Volkman,...

  • catch committed 1691c94 on 8.4.x
    Issue #226873 by Denes.Szabo, rocket_nova, balintd, Albert Volkman,...

Status: Needs work » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.