File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed
src/Symfony/Component/Messenger
Tests/Transport/Serialization Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -76,6 +76,17 @@ public function testEncodedSkipsNonEncodeableStamps()
76
76
$ encoded = $ serializer ->encode ($ envelope );
77
77
$ this ->assertStringNotContainsString ('DummyPhpSerializerNonSendableStamp ' , $ encoded ['body ' ]);
78
78
}
79
+
80
+ public function testNonUtf8IsBase64Encoded ()
81
+ {
82
+ $ serializer = new PhpSerializer ();
83
+
84
+ $ envelope = new Envelope (new DummyMessage ("\xE9" ));
85
+
86
+ $ encoded = $ serializer ->encode ($ envelope );
87
+ $ this ->assertTrue ((bool ) preg_match ('//u ' , $ encoded ['body ' ]), 'Encodes non-UTF8 payloads ' );
88
+ $ this ->assertEquals ($ envelope , $ serializer ->decode ($ encoded ));
89
+ }
79
90
}
80
91
81
92
class DummyPhpSerializerNonSendableStamp implements NonSendableStampInterface
Original file line number Diff line number Diff line change @@ -29,6 +29,10 @@ public function decode(array $encodedEnvelope): Envelope
29
29
throw new MessageDecodingFailedException ('Encoded envelope should have at least a "body". ' );
30
30
}
31
31
32
+ if (false === strpos ($ encodedEnvelope ['body ' ], '} ' , -1 )) {
33
+ $ encodedEnvelope ['body ' ] = base64_decode ($ encodedEnvelope ['body ' ]);
34
+ }
35
+
32
36
$ serializeEnvelope = stripslashes ($ encodedEnvelope ['body ' ]);
33
37
34
38
return $ this ->safelyUnserialize ($ serializeEnvelope );
@@ -43,6 +47,10 @@ public function encode(Envelope $envelope): array
43
47
44
48
$ body = addslashes (serialize ($ envelope ));
45
49
50
+ if (!preg_match ('//u ' , $ body )) {
51
+ $ body = base64_encode ($ body );
52
+ }
53
+
46
54
return [
47
55
'body ' => $ body ,
48
56
];
You can’t perform that action at this time.
0 commit comments