I'm using drupal_http_request() in linkchecker module to verify links. Today I debugged an issue where the UPDATE to MySQL fails. After some investigation it turned out that the error message is not UTF8 encoded and therefore the UPDATE fails.

RAW error message:
Ein Verbindungsversuch ist fehlgeschlagen, da die Gegenstelle nach einer bestimmten Zeitspanne nicht ordnungsgem�� reagiert hat, oder die hergestellte Verbindung war fehlerhaft, da der verbundene Host nicht reagiert hat.

UTF8 encoded error message:
Ein Verbindungsversuch ist fehlgeschlagen, da die Gegenstelle nach einer bestimmten Zeitspanne nicht ordnungsgemäß reagiert hat, oder die hergestellte Verbindung war fehlerhaft, da der verbundene Host nicht reagiert hat.

As you can see there are two special German letters inside that are not properly encoded.

I tried to do a $response->error = drupal_convert_to_utf8($response->error); in linkchecker module and now it seems working, but expect this is not the right way as drupal_convert_to_utf8() requires a second parameter with the source encoding.

I'm not yet sure if the error message is from my local German machine or the remote host!? Are we able to solve this encoding issue inside drupal_http_request()?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

c960657’s picture

Weird. I think the message is generated by fsockopen(), but I wonder why PHP speaks German. Is setlocale() called anywhere? Are you using Windows? What is the output of setlocale(LC_ALL, 0)?

hass’s picture

It returns a C. I'm not using setlocale() myself anywhere... but DEVEL does... it may have been enabled when I have had the issues... cannot remember, but the chances are good. What should this C tell me?

devel.module line 771:

    // We need this for the devel_queries insert below.
    setlocale(LC_NUMERIC, 'C');
c960657’s picture

C is good (the C locale is a minimal English locale), de_DE or similar is bad. The existence of setlocale(LC_MESSAGES, 'de_DE') somewhere would explain the problem. Otherwise I don't know.

hass’s picture

bumping

hass’s picture

Version: 8.x-dev » 7.x-dev
Priority: Major » Normal

Code wise it looks like http://drupal.org/project/httprl has implemented a fix for this bug in httprl_request()...

    // Convert error message to utf-8.
    $errstr = iconv('utf-8', 'utf-8//IGNORE', $errstr);

But drupal_convert_to_utf8() is better.

hass’s picture

Version: 7.x-dev » 8.x-dev
Priority: Normal » Major
xjm’s picture

Version: 7.x-dev » 8.x-dev

I don't believe this meets the criteria for a major bug.

hass’s picture

Status: Active » Needs review
FileSize
1.7 KB

Patch attached is based on last code level of HTTPRL module.

Status: Needs review » Needs work

The last submitted patch, 371495_drupal_http_request_UTF8_bug.patch, failed testing.

hass’s picture

Version: 8.x-dev » 7.x-dev
Status: Needs work » Needs review
hass’s picture

sun’s picture

Status: Needs review » Closed (duplicate)

Sounds like a duplicate of #1561214: Bootstrap sets C locale, but does not set UTF-8 character encoding

See also #614124: Bootstrap should reset locale settings

Feel free to re-open this issue, if I'm mistaken.