Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Results from #search are not marked as UTF-8 in Ruby 1.9.3 #12

Open
keltia opened this issue Mar 13, 2012 · 3 comments
Open

Results from #search are not marked as UTF-8 in Ruby 1.9.3 #12

keltia opened this issue Mar 13, 2012 · 3 comments

Comments

@keltia
Copy link

keltia commented Mar 13, 2012

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":

522 [16:29] roberto@roberto-aw:gems/ruby-ldap-0.9.12> curl http://localhost:3000/user/roberto.yaml

---
!binary "a3Nu":
- !binary |-
  Uk9CRVJU
!binary "a2dpdmVubmFtZQ==":
- !binary |-
  T2xsaXZpZXI=
!binary "dGVsZXBob25lbnVtYmVy":
- !binary |-
  KzMzICgwKTEgNjk4ODcyOTA=
!binary "ZXVyb2NvbnRyb2xyb29taWQ=":
- !binary |-
  Q0MuMjE=
!binary "bWFpbA==":
- !binary |-
  b2xsaXZpZXIucm9iZXJ0QGV1cm9jb250cm9sLmludA==
!binary "dWlk":
- !binary |-
  cm9iZXJ0bw==
!binary "ZXVyb2NvbnRyb2x1bml0Y29kZQ==":
- !binary |-
  RFIvUE0vRlJN
!binary "ZXVyb2NvbnRyb2xncmFkZQ==":
- !binary |-
  QUQxMA==
!binary "ZXVyb2NvbnRyb2xzdGFydGRhdGU=":
- !binary |-
  MTk5Ni8wNy8wMQ==
!binary "ZW1wbG95ZWVudW1iZXI=":
- !binary |-
  MzAzNQ==
!binary "ZXVyb2NvbnRyb2xzaXRlaWQ=":
- !binary |-
  QnJldGlnbnk=

instead of the UTF8 strings.

JSON output through again Treequel is fine:

524 [16:29] roberto@roberto-aw:gems/ruby-ldap-0.9.12> curl http://localhost:3000/user/roberto.json
{"persons":[{"person":["roberto",{"ksn":["ROBERT"],"kgivenname":["Ollivier"],"telephonenumber":["+33 (0)1 69887290"],"eurocontrolroomid":["CC.21"],"mail":["[email protected]"],"uid":["roberto"],"eurocontrolunitcode":["DR/PM/FRM"],"eurocontrolgrade":["AD10"],"eurocontrolstartdate":["1996/07/01"],"employeenumber":["3035"],"eurocontrolsiteid":["Bretigny"]}]}]}%          

NOTE: what is running on port 3000 is my own LDAP proxy, built with Sinatra/Treequel/ruby-ldap:
https://bitbucket.org/keltia/ldap-proxy

@ged
Copy link
Collaborator

ged commented Mar 13, 2012

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>

@ghost
Copy link

ghost commented Mar 14, 2012

hi guys,

I found example of solving encoding problem here
and I think that it can be applied to str here

but problem is that I'm not a C programmer and I'm not sure that it is correct way for solving this problem.

what do you think?

@ghost
Copy link

ghost commented Mar 14, 2012

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>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants