Notice appears when drupal_http_request called with an invalid URL

Aron Novak - July 17, 2008 - 10:37
Project:Drupal
Version:7.x-dev
Component:base system
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed
Description

If someone does this:

drupal_http_request('foo');

a php notice appears and a switch() structure in the function uses a non-existing value.

I'd suggest to check if the URL has scheme before do anything with the scheme.

AttachmentSizeStatusTest resultOperations
drupal_http_request_notice.patch612 bytesIgnoredNoneNone

#1

Dries - July 17, 2008 - 18:03

Does parse_url() return FALSE in that case? If so, I'd check for FALSE. If not, the patch looks good.

#2

Aron Novak - July 17, 2008 - 20:45

<?php
print_r(parse_url('foo'));

Result:
Array
(
    [path] => foo
)

#3

c960657 - July 18, 2008 - 13:48

I suggest also checking whether $uri['host'] is set. The code further down assumes it is.

#4

Dries - July 19, 2008 - 07:32
Status:needs review» needs work

c960657 is right.

#5

mustafau - August 10, 2008 - 16:16
Status:needs work» needs review

I have updated the patch.

AttachmentSizeStatusTest resultOperations
drupal_http_request_notice.patch717 bytesIgnoredNoneNone

#6

Dries - August 12, 2008 - 08:37
Status:needs review» needs work

I've committed this to CVS HEAD and DRUPAL-6. Wouldn't hurt to have some tests for this. Marking it as 'code needs work'.

#7

mustafau - August 12, 2008 - 15:08
Status:needs work» needs review

It seems that when host is not set parse_url returns FALSE so we never get a "missing host" error. Instead of checking for $uri['host'] we should check for FALSE.

A test case is also attached.

AttachmentSizeStatusTest resultOperations
parse_url_error.patch758 bytesIgnoredNoneNone
test_http_request.patch8.65 KBIgnoredNoneNone

#8

Dries - August 13, 2008 - 07:12
Status:needs review» fixed

Tested, reviewed and committed to CVS HEAD. I've also backported this to DRUPAL-6. Thanks for the tests! Let's write some more.

#9

Damien Tournoud - August 13, 2008 - 07:20
Priority:minor» critical
Status:fixed» active

What is the rationale of moving common.test out of includes/tests and to modules/simpletest/tests? Not that I don't support this, but this not seems like the good issue to do that.

#10

mustafau - August 13, 2008 - 09:43

Tests in includes/tests are no longer supported by Simpletest. See this commit: http://drupal.org/cvs?commit=132616

I had to move common.test because there was no other way to make my tests recognized by Simpletest.

#11

catch - August 13, 2008 - 15:31

I get an exception on the drupal_http_request() test:

parse_url(http:///path) [function.parse-url]: Unable to parse URL Warning common.inc 437

#12

c960657 - August 13, 2008 - 17:57

Perhaps valid_url() could be utilized for validating the URL.

That method also has its flaws (see e.g. #124492: valid_url() does not support all valid URL characters or #247880: valid_url needs to support more characters), but it is probably better to fix them rather than having two different ways of validating URLs.

#13

mustafau - August 13, 2008 - 21:12
Status:active» needs review

The exception is unavoidable. I have put an @ operator to that particular function call to suppress the exception. See attached patch.

AttachmentSizeStatusTest resultOperations
test_http_request_exception.patch816 bytesIgnoredNoneNone

#14

catch - August 15, 2008 - 00:02
Status:needs review» reviewed & tested by the community

Patch works good, doesn't affect the test. RTBC.

#15

boombatower - August 15, 2008 - 05:34

Wouldn't it make more sense to but the @ operator on in the actual function instead of in the test?

I have a patch I created before becoming aware of this thread which also has an updated test.

#295564: drupal_http_request triggers error in addition to returning it & test cleanup

#16

Dries - August 15, 2008 - 07:52
Status:reviewed & tested by the community» needs review

Looks like we are still discussing this.

#17

catch - August 15, 2008 - 08:11
Priority:critical» normal
Status:needs review» fixed

Boombatower's patch looks good, and an extra test can't hurt, so back to fixed and we can deal with it in the other issue.

#18

Anonymous (not verified) - August 29, 2008 - 08:12
Status:fixed» closed

Automatically closed -- issue fixed for two weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.