Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/net/ber.rb
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ class Net::BER::BerIdentifiedString < String
def initialize args
super args
# LDAP uses UTF-8 encoded strings
force_encoding('UTF-8') if respond_to?(:encoding)
self.encode('UTF-8') if self.respond_to?(:encoding) rescue self
end
end

Expand Down
27 changes: 27 additions & 0 deletions spec/unit/ber/ber_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,30 @@
end
end
end

describe Net::BER::BerIdentifiedString do
describe "initialize" do
subject { Net::BER::BerIdentifiedString.new(data) }

context "binary data" do
let(:data) { ["6a31b4a12aa27a41aca9603f27dd5116"].pack("H*").force_encoding("ASCII-8BIT") }

its(:valid_encoding?) { should be_true }
specify { subject.encoding.name.should == "ASCII-8BIT" }
end

context "ascii data in UTF-8" do
let(:data) { "some text".force_encoding("UTF-8") }

its(:valid_encoding?) { should be_true }
specify { subject.encoding.name.should == "UTF-8" }
end

context "UTF-8 data in UTF-8" do
let(:data) { ["e4b8ad"].pack("H*").force_encoding("UTF-8") }

its(:valid_encoding?) { should be_true }
specify { subject.encoding.name.should == "UTF-8" }
end
end
end