|
40 | 40 | let(:expected_file_contents) { "GIF89a\u0001\u0000\u0001\u0000\u0000\xFF\u0000,\u0000\u0000\u0000\u0000\u0001\u0000\u0001\u0000\u0000\u0002\u0000;" } |
41 | 41 | let(:expected_content_type) { 'image/gif' } |
42 | 42 | let(:multipart_params) do |
43 | | - "--------------------------c772861a5109d5ef\r\n" \ |
| 43 | + ("--------------------------c772861a5109d5ef\r\n" \ |
44 | 44 | "Content-Disposition: form-data; name=\"user[avatar]\"; filename=\"#{expected_file_name}\"\r\n" \ |
45 | 45 | "Content-Type: #{expected_content_type}\r\n" \ |
46 | 46 | "\r\n" \ |
|
57 | 57 | "Content-Disposition: form-data; name=\"user[enabled]\"\r\n" \ |
58 | 58 | "\r\n" \ |
59 | 59 | "true\r\n" \ |
60 | | - "--------------------------c772861a5109d5ef--\r\n" |
| 60 | + "--------------------------c772861a5109d5ef--\r\n").b |
61 | 61 | end |
62 | 62 |
|
63 | 63 | it { is_expected.to eq multipart_params } |
|
76 | 76 | } |
77 | 77 | end |
78 | 78 | let(:multipart_params) do |
79 | | - "--------------------------c772861a5109d5ef\r\n" \ |
| 79 | + ("--------------------------c772861a5109d5ef\r\n" \ |
80 | 80 | "Content-Disposition: form-data; name=\"user[first_name]\"\r\n" \ |
81 | 81 | "\r\n" \ |
82 | 82 | "John\r\n" \ |
|
88 | 88 | "Content-Disposition: form-data; name=\"user[enabled]\"\r\n" \ |
89 | 89 | "\r\n" \ |
90 | 90 | "true\r\n" \ |
91 | | - "--------------------------c772861a5109d5ef--\r\n" |
| 91 | + "--------------------------c772861a5109d5ef--\r\n").b |
92 | 92 | end |
93 | 93 |
|
94 | 94 | it { is_expected.to eq multipart_params } |
|
122 | 122 | } |
123 | 123 | end |
124 | 124 | let(:multipart_params) do |
125 | | - "--------------------------c772861a5109d5ef\r\n" \ |
| 125 | + ("--------------------------c772861a5109d5ef\r\n" \ |
126 | 126 | "Content-Disposition: form-data; name=\"user[attachment_file]\"; filename=\"#{expected_file_name}\"\r\n" \ |
127 | 127 | "Content-Type: text/plain\r\n" \ |
128 | 128 | "\r\n" \ |
|
131 | 131 | "Content-Disposition: form-data; name=\"user[enabled]\"\r\n" \ |
132 | 132 | "\r\n" \ |
133 | 133 | "true\r\n" \ |
134 | | - "--------------------------c772861a5109d5ef--\r\n" |
| 134 | + "--------------------------c772861a5109d5ef--\r\n").b |
135 | 135 | end |
136 | 136 |
|
137 | 137 | it { is_expected.to eq multipart_params } |
|
148 | 148 | } |
149 | 149 | end |
150 | 150 |
|
151 | | - it { expect { subject }.not_to raise_error } |
| 151 | + it 'does not raise encoding errors' do |
| 152 | + expect { subject }.not_to raise_error |
| 153 | + end |
| 154 | + |
| 155 | + it 'produces valid binary multipart body' do |
| 156 | + result = subject |
| 157 | + expect(result.encoding).to eq(Encoding::BINARY) |
| 158 | + expect(result).to include("Jöhn Döé".b) |
| 159 | + end |
| 160 | + |
| 161 | + it 'concatenates binary file data with UTF-8 text without corruption' do |
| 162 | + result = subject |
| 163 | + # Should contain both the UTF-8 user field and binary GIF data |
| 164 | + expect(result).to include('Content-Disposition: form-data; name="user"'.b) |
| 165 | + expect(result).to include("Jöhn Döé".b) |
| 166 | + expect(result).to include('Content-Disposition: form-data; name="avatar"'.b) |
| 167 | + expect(result).to include("GIF89a".b) # GIF file header |
| 168 | + end |
152 | 169 | end |
153 | 170 | end |
154 | 171 | end |
|
0 commit comments