Skip to content

Commit dc175e1

Browse files
authored
Merge pull request #239 from MohKamal/fix/mohkamal_adding_utf_8_encoding
adding utf8 encoding to documents data
2 parents 1c42790 + 73c01bc commit dc175e1

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

ravendb/http/request_executor.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,10 @@ def __create_request(self, node: ServerNode, command: RavenCommand) -> Optional[
907907
request = command.create_request(node)
908908
# todo: optimize that if - look for the way to make less ifs each time
909909
if request.data and not isinstance(request.data, str) and not inspect.isgenerator(request.data):
910-
request.data = json.dumps(request.data, default=self.conventions.json_default_method)
910+
# Making sur that all documents are utf-8 decoded, avoiding any bizzar caracters in the database documents
911+
request.data = json.dumps(
912+
request.data, default=self.conventions.json_default_method, ensure_ascii=False
913+
).encode("utf-8")
911914

912915
# todo: 1117 - 1133
913916
return request or None

ravendb/tests/jvm_migrated_tests/client_tests/documents_tests/commands_tests/test_put_document_command.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@
66
from ravendb.tools.utils import Utils
77

88

9+
class Article:
10+
def __init__(
11+
self,
12+
Id: str = None,
13+
title: str = None,
14+
):
15+
self.Id = Id
16+
self.title = title
17+
18+
919
class TestPutDocumentCommand(TestBase):
1020
def setUp(self):
1121
super().setUp()
@@ -27,9 +37,9 @@ def test_can_put_document_using_command(self):
2737
loaded_user = session.load("users/1", User)
2838
self.assertEqual(loaded_user.name, "Gracjan")
2939

30-
@unittest.skip("todo: Not passing on CI/CD")
40+
# @unittest.skip("todo: Not passing on CI/CD")
3141
def test_can_put_document_using_command_with_surrogate_pairs(self):
32-
name_with_emojis = "Gracjan \ud83d\ude21\ud83d\ude21\ud83e\udd2c\ud83d\ude00😡😡🤬😀"
42+
name_with_emojis = "Gracjan 😡😡🤬😀"
3343

3444
user = User(name=name_with_emojis, age=31)
3545
node = Utils.entity_to_dict(user, self.store.conventions.json_default_method)
@@ -45,3 +55,21 @@ def test_can_put_document_using_command_with_surrogate_pairs(self):
4555
with self.store.open_session() as session:
4656
loaded_user = session.load("users/2", User)
4757
self.assertEqual(loaded_user.name, name_with_emojis)
58+
59+
def test_can_put_document_using_command_with_utf_8_chars(self):
60+
title_with_emojis = (
61+
"Déposer un CAPITAL SOCIAL : ce que tu dois ABSOLUMENT comprendre avant de lancer une ENTREPRISE 🏦"
62+
)
63+
64+
article = Article(title=title_with_emojis)
65+
node = Utils.entity_to_dict(article, self.store.conventions.json_default_method)
66+
command = PutDocumentCommand("articles/1", None, node)
67+
self.store.get_request_executor().execute_command(command)
68+
69+
result = command.result
70+
71+
self.assertIsNotNone(result.change_vector)
72+
73+
with self.store.open_session() as session:
74+
loaded_article = session.load("articles/1", Article)
75+
self.assertEqual(loaded_article.title, title_with_emojis)

0 commit comments

Comments
 (0)