ruby-net-ldap icon indicating copy to clipboard operation
ruby-net-ldap copied to clipboard

Complete support for UTF-8

Open RoryO opened this issue 14 years ago • 10 comments

Internally we're still assuming ASCII-8 on all string, so when doing manipulations between a UTF-8 response from the server and internal strings it will fail with EncodingError on 1.9.

This is likely going to be a huge overhaul and should be a release in itself.

RoryO avatar May 29 '11 21:05 RoryO

We're using this Gem and the names of the users have unwanted characters, when we should have Latin characters. I guess this is due to the UTF-8 / ASCII-8 conversion.

Is there a workaround for this?

Thanks.

gamafranco avatar Jan 09 '12 17:01 gamafranco

Could you give an example on what's actually in the LDAP server, and the incorrect string that's getting returned?

RoryO avatar Jan 09 '12 22:01 RoryO

Hi,

Thanks you for your time.

For example, in the LDAP server I have "Inês Gonçalves" and I get "In\xC3\xAAs Gon\xC3\xA7alves".

gamafranco avatar Jan 10 '12 12:01 gamafranco

We also encountered this issue.

As a workaround: the gem seems to be returning valid UTF-8 text, just in the wrong encoding -- i.e., using force_encoding("UTF-8") on the results returned from LDAP will yield properly encoded text (I've been testing this with Japanese text).

(Ironically, plain ASCII text will be encoded in UTF-8 already, so the force_encoding shouldn't cause issues where there already wasn't one.)

doubt72 avatar Apr 25 '12 19:04 doubt72

Thanks! It works.

gamafranco avatar Apr 28 '12 20:04 gamafranco

I've also seen this now. Doing like this:

user = ldap.search(
  base: filter_base,
  filter: user_filter,
  attributes: ['samaccountname', 'displayname', 'memberof']
).first
{
  username: user.samaccountname.first,
  name: user.displayname.first.force_encoding('UTF-8')
}

...works, but it's incredibly ugly to have to force encoding like that. Without it, it "works" for users with ASCII (7-bit) safe names, but users with e.g. scandinavian umlauts (åäö) get problems. (#<Encoding::InvalidByteSequenceError: ""\xC3"" on ASCII-8BIT>) when trying to convert the string to JSON)

Is there a plan to resolve this proper in net-ldap at some point? :+1: from my end on such a thing...

perlun avatar Apr 25 '14 08:04 perlun

Get the same result on ruby 2.1.6, net-ldap 0.11, windows 8.1 x64 I connect to a French AD server and need to force encoding to UTF-8. (same remark as @doubt72)

ldap returned string "Frédéric" in ASCII-8BIT and I compared it with "Frédéric" in UTF-8 and it matched never.....

Any progress to resolve this is welcome !

net1957 avatar Jun 19 '15 22:06 net1957

@RoryO - care to provide some more details on why this was closed? Has this been fixed, and if so, in what PR?

perlun avatar Jul 05 '16 20:07 perlun

I encountered the same problem on version 0.12.0. Like @net1957, french LDAP too, problem coming from characters like 'ç', 'é' or 'è'.

For those interested, this bug was fixed directly in Redmine : https://www.redmine.org/issues/21453 with this patch : https://www.redmine.org/projects/redmine/repository/revisions/15025/diff/trunk/app/models/auth_source_ldap.rb

vincent-clipet avatar Nov 15 '16 09:11 vincent-clipet

I am having the same issue regarding underscores...

chrishough avatar Aug 14 '19 05:08 chrishough