Encoding::UndefinedConversionError

1,168 views
Skip to first unread message

Ajedi32

unread,
Jul 19, 2012, 4:54:17 PM7/19/12
to ruby...@googlegroups.com
I recently started trying to implement a LDAP-based login system in my Rails application, but whenever I try to run a basic LDAP query I get the following error:

Encoding::UndefinedConversionError: "\x82" from ASCII-8BIT to UTF-8
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/net-ldap-0.3.1/lib/net/ber/core_ext/string.rb:23:in `encode'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/net-ldap-0.3.1/lib/net/ber/core_ext/string.rb:23:in `raw_utf8_encoded'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/net-ldap-0.3.1/lib/net/ber/core_ext/string.rb:15:in `to_ber'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/net-ldap-0.3.1/lib/net/ldap.rb:1396:in `block in search'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/net-ldap-0.3.1/lib/net/ldap.rb:1367:in `loop'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/net-ldap-0.3.1/lib/net/ldap.rb:1367:in `search'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/net-ldap-0.3.1/lib/net/ldap.rb:637:in `search'
        from C:/Documents and Settings/meyer.a/My Documents/Workspace/Training Hub/Training Hub Workspace/training_hub/app/models/user.rb:32:in `all'
        from (irb):29
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/commands/console.rb:47:in `start'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/commands/console.rb:8:in `start'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/commands.rb:41:in `<top (required)>'
        from script/rails:6:in `require'
        from script/rails:6:in `<main>'

It seems to be triggered whenever net-ldap hits a certain record in the ldap database (though I can't really tell which one). Here's the code I'm running that triggers the error. It always gets to a certain point and then errors out:

    test = LDAP.search(
      base: BASE_ROOT, # This is defined elsewhere in my code.
      attributes: ["mail"],
      filter: Net::LDAP::Filter.eq("objectClass", "person"),
      return_result: true,
      size:300
    ) do |entry|
      puts "DN: #{entry.dn}"
      entry.each do |attribute, values|
        puts "   #{attribute}:"
        values.each do |value|
          puts "      --->#{value}"
        end
      end
    end

Is this a bug? Or is there something I'm doing wrong?

Ajedi32

unread,
Jul 20, 2012, 11:21:57 AM7/20/12
to ruby...@googlegroups.com
I figured out how to solve the problem, this is indeed a bug: https://github.com/ruby-ldap/ruby-net-ldap/pull/44

I'll be using krogebry's branch of net-ldap until this problem is fixed.

krogebry

unread,
Jul 20, 2012, 1:32:28 PM7/20/12
to ruby...@googlegroups.com
Glad I could help!

I tracked this down to ( I think ) some Microsoft specific garbage in one of the returned fields.

Now I'm trying to figure out how to get my patch rolled into the next rev.

On Friday, July 20, 2012 8:21:57 AM UTC-7, Ajedi32 wrote:
> I figured out how to solve the problem, this is indeed a bug: <a href="https://github.com/ruby-ldap/ruby-net-ldap/pull/44" target="_blank">https://github.com/ruby-<WBR>ldap/ruby-net-ldap/pull/44</a>
>
> </div>
> I&#39;ll be using <a href="https://github.com/krogebry" style="color:rgb(102,102,102);text-decoration:underline;font-weight:bold;font-family:Helvetica,arial,freesans,clean,sans-serif;font-size:12px;line-height:16px" target="_blank">krogebry</a>&#39;s branch of net-ldap until this problem is fixed.
> </div>

Reply all
Reply to author
Forward
0 new messages