Open keltia opened 12 years ago
I've confirmed that data comes out of Ruby-LDAP as ASCII-8BIT, which is why Treequel's strings have that encoding:
[1] pry(main)> require 'ldap'
=> true
[2] pry(main)> c = LDAP::SSLConn.new( 'ldap.example.com', 389, true )
=> #<LDAP::SSLConn:0x007fc7c30f8420
@args=["ldap.example.com", 389, true],
@sasl_quiet=false>
[3] pry(main)> res = c.search_ext2( 'dc=example,dc=com', LDAP::LDAP_SCOPE_SUBTREE, '(uid=mgranger)' )
=> [{"dn"=>["uid=mgranger,ou=People,dc=example,dc=com"], [...]}]
[4] pry(main)> res.first['cn']
=> ["Michael Granger"]
[5] pry(main)> res.first['cn'].first.encoding
=> #<Encoding:ASCII-8BIT>
looks like it is bad idea... :)
1.9.3p125 :001 > require 'ldap'
=> true
1.9.3p125 :002 > c = LDAP::Conn.new( 'localhost', 389 )
=> #<LDAP::Conn:0x007fafcb06f810>
1.9.3p125 :003 > res = c.search_ext2( 'dc=localhost,dc=com', LDAP::LDAP_SCOPE_SUBTREE, '(cn=admin)' )
=> [{"dn"=>["cn=admin,dc=localhost,dc=com"], "objectClass"=>["\u0005\x81\u0004"], "cn"=>["\u0005A\u0001"]}]
1.9.3p125 :004 > res.first['cn']
=> ["\u0005A\u0001"]
1.9.3p125 :005 > res.first['cn'].first.encoding
=> #<Encoding:UTF-8>
When trying to convert into YAML the values I get from my LDAP server through Treequel, strings are not marked as UTF-8 in Ruby 1.9.3 resulting in everything marked as "BINARY":
instead of the UTF8 strings.
JSON output through again Treequel is fine:
NOTE: what is running on port 3000 is my own LDAP proxy, built with Sinatra/Treequel/ruby-ldap: https://bitbucket.org/keltia/ldap-proxy