Skip to content
This repository was archived by the owner on Oct 5, 2023. It is now read-only.

Commit

Permalink
Added condition to not force encoding on existing ASCII
Browse files Browse the repository at this point in the history
  • Loading branch information
phene committed Jun 21, 2012
1 parent 9fa3138 commit 8812bc1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/net/ber/core_ext/string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def to_ber(code = 0x04)
end

def raw_utf8_encoded
if self.respond_to?(:encode)
if self.respond_to?(:encode) && self.encoding.name != 'ASCII-8BIT'
# Strings should be UTF-8 encoded according to LDAP.
# However, the BER code is not necessarily valid UTF-8
self.encode('UTF-8').force_encoding('ASCII-8BIT')
Expand Down
6 changes: 6 additions & 0 deletions test/test_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ def test_invalid_filter
Filter.__send__(:new, :xx, nil, nil)
}
end

def test_raw_utf8_encoded_on_ascii
assert_nothing_raised do
"0\r\x02\x01~\x04\b\x00\x00\x00\x00\x00\x01\x87\"".send :raw_utf8_encoded
end
end

def test_to_s
assert_equal("(uid=george *)", Filter.eq("uid", "george *").to_s)
Expand Down

0 comments on commit 8812bc1

Please sign in to comment.