File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -298,7 +298,7 @@ class Net::BER::BerIdentifiedString < String
298
298
def initialize args
299
299
super args
300
300
# LDAP uses UTF-8 encoded strings
301
- force_encoding ( 'UTF-8' ) if respond_to? ( :encoding )
301
+ self . encode ( 'UTF-8' ) if self . respond_to? ( :encoding ) rescue self
302
302
end
303
303
end
304
304
Original file line number Diff line number Diff line change 112
112
end
113
113
end
114
114
end
115
+
116
+ describe Net ::BER ::BerIdentifiedString do
117
+ describe "initialize" do
118
+ subject { Net ::BER ::BerIdentifiedString . new ( data ) }
119
+
120
+ context "binary data" do
121
+ let ( :data ) { [ "6a31b4a12aa27a41aca9603f27dd5116" ] . pack ( "H*" ) . force_encoding ( "ASCII-8BIT" ) }
122
+
123
+ its ( :valid_encoding? ) { should be_true }
124
+ specify { subject . encoding . name . should == "ASCII-8BIT" }
125
+ end
126
+
127
+ context "ascii data in UTF-8" do
128
+ let ( :data ) { "some text" . force_encoding ( "UTF-8" ) }
129
+
130
+ its ( :valid_encoding? ) { should be_true }
131
+ specify { subject . encoding . name . should == "UTF-8" }
132
+ end
133
+
134
+ context "UTF-8 data in UTF-8" do
135
+ let ( :data ) { [ "e4b8ad" ] . pack ( "H*" ) . force_encoding ( "UTF-8" ) }
136
+
137
+ its ( :valid_encoding? ) { should be_true }
138
+ specify { subject . encoding . name . should == "UTF-8" }
139
+ end
140
+ end
141
+ end
You can’t perform that action at this time.
0 commit comments