Skip to content

Commit 6d49384

Browse files
authored
Merge pull request #19 from SimplyEdit/fix/issue-12-non-ASCII-characters
Fix issue caused by missing invalid UTF-8 handling.
2 parents ec2a3e3 + ee47a4c commit 6d49384

2 files changed

Lines changed: 21 additions & 12 deletions

File tree

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88
"email": "auke@muze.nl"
99
}],
1010
"require": {
11+
"ext-json": "*"
1112
}
1213
}

www/simply-edit/http.php

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,22 @@ private static function parseAuthUser($auth) {
5050

5151
public static function getUser()
5252
{
53-
$checks = [
54-
'PHP_AUTH_USER' => false,
55-
'REMOTE_USER' => false,
53+
$checks = [
54+
'PHP_AUTH_USER' => false,
55+
'REMOTE_USER' => false,
5656
'HTTP_AUTHORIZATION' => function($auth) { return self::parseAuthUser($auth); },
5757
];
5858
list($header, $headerValue) = self::getHeader($checks, 3);
59-
if (is_array($checks[$header])) {
59+
if (isset($checks[$header]) && is_array($checks[$header])) {
6060
$headerValue = call_user_func($checks[$header], $headerValue)[0];
6161
}
6262
return $headerValue;
6363
}
6464

6565
public static function getPassword()
6666
{
67-
$checks = [
68-
'PHP_AUTH_PW' => false,
67+
$checks = [
68+
'PHP_AUTH_PW' => false,
6969
'HTTP_AUTHORIZATION' => function($auth) { return self::parseAuthUser($auth); },
7070
];
7171
list($header, $headerValue) = self::getHeader($checks, 3);
@@ -120,14 +120,22 @@ public static function response($status, $data='')
120120
case 'html':
121121
echo $data;
122122
break;
123-
case 'svg':
124-
header('Content-type: image/svg+xml');
125-
echo $data;
126-
break;
123+
case 'svg':
124+
header('Content-type: image/svg+xml');
125+
echo $data;
126+
break;
127+
case 'text':
128+
header('Content-Type: text/plain');
129+
echo $data;
130+
break;
131+
case 'rawjson':
132+
header('Content-Type: application/json');
133+
echo $data;
134+
break;
127135
case 'json':
128136
default:
129-
header('Content-type: application/json');
130-
echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR);
137+
header('Content-Type: application/json');
138+
echo json_encode($data, JSON_INVALID_UTF8_IGNORE | JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR);
131139
break;
132140
}
133141
}

0 commit comments

Comments
 (0)