Item12021: LdapContrib: baseDN has wrong encoding in searches

pencil
Priority: Normal
Current State: Closed
Released In: n/a
Target Release: n/a
Applies To: Extension
Component: LdapContrib
Branches: trunk
Reported By: JanKrueger
Waiting For:
Last Change By: MichaelDaum
in sub search in LdapContrib.pm, the base arg is passed on unchanged... which means that the encoding will most probably end up being ISO-8859-1. Specifically, when I ran into an issue, what happened was this:

  • Base DN contains non-ASCII characters.
  • Base DN string ends up being a Perl Unicode string (for whatever reason).
  • When the query is sent to the LDAP server, Perl's I/O layer defaults to encoding Perl Unicode strings as ISO-8859-1.

An ugly but simple solution might be to encode the string into a UTF-8 byte string prior to sending it out, like this:

diff --git a/lib/Foswiki/Contrib/LdapContrib.pm b/lib/Foswiki/Contrib/LdapContrib.pm
index 9fb601a..429f933 100644
--- a/lib/Foswiki/Contrib/LdapContrib.pm
+++ b/lib/Foswiki/Contrib/LdapContrib.pm
@@ -540,6 +540,7 @@ sub search {
   my ($this, %args) = @_;
 
   $args{base} = $this->{base} unless $args{base};
+  $args{base} = toUtf8($args{base});
   $args{scope} = 'sub' unless $args{scope};
   $args{sizelimit} = 0 unless $args{sizelimit};
   $args{attrs} = ['*'] unless $args{attrs};
@@ -2356,7 +2357,8 @@ sub toUtf8 {
   my ($this, $string) = @_;
 
   my $charset = $Foswiki::cfg{Site}{CharSet};
-  return $string if $charset =~ /^utf-?8$/i;
+  # Item12021: make sure that even if it's already UTF-8, we definitely get a byte string
+  return $string if $charset =~ /^utf-?8$/i && ($] < 5.008 || !Encode::is_utf8($string));
 
   if ($] < 5.008) {

-- JanKrueger - 30 Jul 2012

 
Topic revision: r3 - 19 Nov 2012, MichaelDaum
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy