Skip to content

Commit 9e1487d

Browse files
Fix json_encode for unicode(emoji) characters
1 parent e91a436 commit 9e1487d

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

src/Elasticsearch/Serializers/ArrayToJSONSerializer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function serialize($data)
2929
if (is_string($data) === true) {
3030
return $data;
3131
} else {
32-
$data = json_encode($data, JSON_PRESERVE_ZERO_FRACTION);
32+
$data = json_encode($data, JSON_PRESERVE_ZERO_FRACTION + JSON_INVALID_UTF8_SUBSTITUTE);
3333
if ($data === false) {
3434
throw new RuntimeException("Failed to JSON encode: ".json_last_error());
3535
}

src/Elasticsearch/Serializers/EverythingToJSONSerializer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class EverythingToJSONSerializer implements SerializerInterface
2626
*/
2727
public function serialize($data)
2828
{
29-
$data = json_encode($data, JSON_PRESERVE_ZERO_FRACTION);
29+
$data = json_encode($data, JSON_PRESERVE_ZERO_FRACTION + JSON_INVALID_UTF8_SUBSTITUTE);
3030
if ($data === false) {
3131
throw new RuntimeException("Failed to JSON encode: ".json_last_error());
3232
}

src/Elasticsearch/Serializers/SmartSerializer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function serialize($data)
3030
if (is_string($data) === true) {
3131
return $data;
3232
} else {
33-
$data = json_encode($data, JSON_PRESERVE_ZERO_FRACTION);
33+
$data = json_encode($data, JSON_PRESERVE_ZERO_FRACTION + JSON_INVALID_UTF8_SUBSTITUTE);
3434
if ($data === false) {
3535
throw new Exceptions\RuntimeException("Failed to JSON encode: ".json_last_error());
3636
}

0 commit comments

Comments
 (0)