From c95bee25013a323d5feef54f8649596c64096b12 Mon Sep 17 00:00:00 2001 From: Nikolai Kristiansen Date: Sun, 13 Jul 2014 17:43:05 +0200 Subject: [PATCH] UTF-8 / latin1-fixes --- snapporder/lib/CryptoHelper.php | 2 +- snapporder/lib/functions.php | 7 +++++++ snapporder/tests/integration.php | 7 ++++--- snapporder/tests/integration.sh | 2 +- snapporder/tests/testuser.json | 8 ++++---- 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/snapporder/lib/CryptoHelper.php b/snapporder/lib/CryptoHelper.php index 02734a9..cee565b 100644 --- a/snapporder/lib/CryptoHelper.php +++ b/snapporder/lib/CryptoHelper.php @@ -44,7 +44,7 @@ class CryptoHelper mcrypt_generic_deinit($td); mcrypt_module_close($td); - return utf8_encode(trim($decrypted)); + return trim($decrypted); } private function hex2bin($hexdata) diff --git a/snapporder/lib/functions.php b/snapporder/lib/functions.php index cd02a16..4e704b5 100644 --- a/snapporder/lib/functions.php +++ b/snapporder/lib/functions.php @@ -40,6 +40,9 @@ function add_user($data) { $cols = array_keys($data); $values = array_values($data); + // FIXME: Decode UTF-8 values... why? + $values = array_map("utf8_decode", $values); + $sth = $conn->autoPrepare("din_user", $cols, DB_AUTOQUERY_INSERT); $res = $conn->execute($sth, $values); @@ -115,6 +118,10 @@ function get_user($user_id) { unset($user['birthdate']); } + /* FIXME: Double encode fields as utf-8... why? */ + foreach($user as $key => $value) { + $user[$key] = utf8_encode($value); + } return $user; } function get_user_id_by_username($username) { diff --git a/snapporder/tests/integration.php b/snapporder/tests/integration.php index acb7e42..8327c56 100644 --- a/snapporder/tests/integration.php +++ b/snapporder/tests/integration.php @@ -37,13 +37,14 @@ function test_post_register() { curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json ')); + curl_setopt($ch, CURLOPT_ENCODING ,""); + curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=UTF-8')); $result = curl_exec($ch); $result = $crypt->decrypt(trim($result)); - $decoded_result = json_decode($result); + $decoded_result = (array) json_decode($result); - if(!isset($decoded_result->error)) { + if(isset($decoded_result['birthdate']) && $decoded_result['birthdate'] === "1983-01-01") { echo "OK"; var_dump($decoded_result); } else { diff --git a/snapporder/tests/integration.sh b/snapporder/tests/integration.sh index 7eefc52..996a09b 100755 --- a/snapporder/tests/integration.sh +++ b/snapporder/tests/integration.sh @@ -1,5 +1,5 @@ #!/bin/sh HOST="http://inside.dev" -curl -XPOST -H"Content-type: application/json" --data-binary @testuser.json $HOST/snapporder/api/register.php +curl -XPOST -H"Content-type: application/json; charset=UTF-8" --data-binary @testuser.json $HOST/snapporder/api/register.php diff --git a/snapporder/tests/testuser.json b/snapporder/tests/testuser.json index 6752243..48f3409 100644 --- a/snapporder/tests/testuser.json +++ b/snapporder/tests/testuser.json @@ -1,7 +1,7 @@ { "firstname": "Üve", - "lastname": "Bårdvigsen", - "email": "aaaadadfzooaaa@aaa422asd333a44za.com", - "birthdate": "1985-02-05", - "phone": "+4745199787" + "lastname": "Bårdvigsen Røed", + "email": "aaaabazbasdfbfffaaaaaba@aaa44za.com", + "birthdate": "1983-01-01", + "phone": "+4743989787" }