This repository was archived by the owner on Nov 30, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +45
-0
lines changed Expand file tree Collapse file tree 2 files changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -32,8 +32,17 @@ def publish(event, *args)
32
32
# parent process.
33
33
# @private
34
34
class Channel
35
+ if String . method_defined? ( :encoding )
36
+ MARSHAL_DUMP_ENCODING = Marshal . dump ( "" ) . encoding
37
+ end
38
+
35
39
def initialize
36
40
@read_io , @write_io = IO . pipe
41
+
42
+ if defined? ( MARSHAL_DUMP_ENCODING ) && IO . method_defined? ( :set_encoding )
43
+ # Ensure the pipe is able to send any content produced by Marshal.dump
44
+ @write_io . set_encoding MARSHAL_DUMP_ENCODING
45
+ end
37
46
end
38
47
39
48
def send ( message )
Original file line number Diff line number Diff line change @@ -36,5 +36,41 @@ def foo(notification); end
36
36
37
37
expect ( channel . receive ) . to eq :value_from_child
38
38
end
39
+
40
+ describe "in a UTF-8 encoding context (where possible)" do
41
+ if defined? ( Encoding )
42
+ around ( :each ) do |example |
43
+ old_external = old_internal = nil
44
+
45
+ ignoring_warnings do
46
+ old_external , Encoding . default_external = Encoding . default_external , Encoding ::UTF_8
47
+ old_internal , Encoding . default_internal = Encoding . default_internal , Encoding ::UTF_8
48
+ end
49
+
50
+ example . run
51
+
52
+ ignoring_warnings do
53
+ Encoding . default_external = old_external
54
+ Encoding . default_internal = old_internal
55
+ end
56
+ end
57
+ end
58
+
59
+ it "successfully sends binary data within a process" do
60
+ channel = Bisect ::Channel . new
61
+ expect { channel . send ( "\xF8 " ) } . not_to raise_error
62
+ end
63
+
64
+ it "successfully sends binary data from a child process to its parent process" do
65
+ channel = Bisect ::Channel . new
66
+
67
+ in_sub_process do
68
+ channel . send ( "\xF8 " )
69
+ end
70
+
71
+ expect ( channel . receive ) . to eq ( "\xF8 " )
72
+ end
73
+ end
74
+
39
75
end
40
76
end
You can’t perform that action at this time.
0 commit comments