1

I'm working with a payment gateway that returns payment feedback in the URL. One of the variables has a special character in it:

PM=Sofort+%DCberweisung

The %DC is Ü. However, it's coming through instead as �—and in case that doesn't display properly here, it's a black triangle with a question mark inside it. I confirmed this by replacing my menu callback with a simple print and die:

print($_GET['PM']); die();

The output is just (again: I'm not sure how that broken character might appear here on StackExchange):

Sofort �berweisung (DE)

I have confirmed that if I replace the %DC in the URL with Ü, it prints fine, so it's not a problem with that character: something is going wrong, somewhere, when the server tries to decode the URL-encoded value.

Does Drupal do any kind of processing on $_GET variables during bootstrapping? Could this be an Apache configuration issue?

Update: This is definitely something in Drupal. I moved my print-then-die to the very beginning of index.php and it prints the correct value. This tells me that it's not an Apache problem. Then, on a clean D6 install with no contrib modules, I added a small module that just adds a single menu callback to do that same print-then-die, and I got the invalid character there.

  • This is definitely an encoding issue. It's fine if I run the variable through utf8_encode(), but I can't figure out where Drupal would be converting it from UTF-8 to ISO-8859-1. – Brock Boland Nov 21 '11 at 17:30
  • 2
    Drupal performs no conversion on $_GET at all - %DC is just a byte sequence. The conversion is being done by your browser, and it's triggered by the presence of the <meta charset="utf-8" /> in the head. When you die() right away in index.php, you prevent the charset meta element from being output, so your browser guesses ISO-8859 and you see Ü. – Dylan Tack Nov 22 '11 at 0:02
2

Sounds like your incoming data is ISO-8859-1, not the other way round. Drupal is always in UTF-8 (and utf8_encode converts from ISO-8859-1 to UTF8).

This is what I get when urlencoding Ü.:

$ drush ev 'var_dump(urlencode('ü'));'
string(6) "%C3%BC"

And when urldecoding and utf8 encoding %DC:

$ drush ev "var_dump(utf8_encode(urldecode('%DC')));"
string(2) "Ü"

Makes all perfect sense to me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.