Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fall back if string cannot be encoded #41

Merged
merged 1 commit into from

4 participants

@justcfx2u

This patch makes searching for "(objectclass=user)" on my ActiveDirectory behave itself. Something in the LDAP directory was failing terribly, which was allowing searches by "(cn=[a-z]*)", but would fail on a filter for "(objectclass=user)".

This quick'n'dirty patch resolved my issue.

I use it in combination with Pull Request 33 (#33).

@justcfx2u

Could possibly be shortened to:

self.encode('UTF-8').force_encoding('ASCII-8BIT') rescue self

When will the be released to Rubygems? Thanks

@shanepinnell

Worked for me...

@RoryO RoryO merged commit ccd7b6d into ruby-ldap:master
@chuckbjones chuckbjones referenced this pull request
Closed

UTF-8 encoding fix. #44

@satoryu satoryu referenced this pull request from a commit in satoryu/ruby-net-ldap
@satoryu satoryu Fix Invalid examples
1. String#encode should not fail if given an invalid code like '\x81'
This is because this problem has been resolved by #41.

2. Net::LDAP#search should return a boolean if return_result is false.
b6c6dda
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 5 additions and 1 deletion.
  1. +5 −1 lib/net/ber/core_ext/string.rb
View
6 lib/net/ber/core_ext/string.rb
@@ -20,7 +20,11 @@ def raw_utf8_encoded
if self.respond_to?(:encode)
# 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')
+ begin
+ self.encode('UTF-8').force_encoding('ASCII-8BIT')
+ rescue Encoding::UndefinedConversionError
+ self
+ end
else
self
end
Something went wrong with that request. Please try again.