]> granicus.if.org Git - ejabberd/commitdiff
Work also with some unicode strings in PgSQL (EJAB-1490)
authorBadlop <badlop@process-one.net>
Tue, 14 Feb 2012 12:18:18 +0000 (13:18 +0100)
committerBadlop <badlop@process-one.net>
Tue, 14 Feb 2012 12:18:18 +0000 (13:18 +0100)
src/mod_vcard.erl
src/mod_vcard_odbc.erl

index 1820f64b88958c9230138040c18f1434f0e8135f..46830b0200b1f47d58a3196cd4992500d5bbd391 100644 (file)
@@ -219,17 +219,17 @@ set_vcard(User, LServer, VCARD) ->
            end,
 
     LUser     = jlib:nodeprep(User),
-    LFN       = string:to_lower(FN),
-    LFamily   = string:to_lower(Family),
-    LGiven    = string:to_lower(Given),
-    LMiddle   = string:to_lower(Middle),
-    LNickname = string:to_lower(Nickname),
-    LBDay     = string:to_lower(BDay),
-    LCTRY     = string:to_lower(CTRY),
-    LLocality = string:to_lower(Locality),
-    LEMail    = string:to_lower(EMail),
-    LOrgName  = string:to_lower(OrgName),
-    LOrgUnit  = string:to_lower(OrgUnit),
+    LFN       = string2lower(FN),
+    LFamily   = string2lower(Family),
+    LGiven    = string2lower(Given),
+    LMiddle   = string2lower(Middle),
+    LNickname = string2lower(Nickname),
+    LBDay     = string2lower(BDay),
+    LCTRY     = string2lower(CTRY),
+    LLocality = string2lower(Locality),
+    LEMail    = string2lower(EMail),
+    LOrgName  = string2lower(OrgName),
+    LOrgUnit  = string2lower(OrgUnit),
 
     US = {LUser, LServer},
 
@@ -271,6 +271,12 @@ set_vcard(User, LServer, VCARD) ->
            ejabberd_hooks:run(vcard_set, LServer, [LUser, LServer, VCARD])
     end.
 
+string2lower(String) ->
+    case stringprep:tolower(String) of
+        Lower when is_list(Lower) -> Lower;
+        error -> string:to_lower(String)
+    end.
+
 -define(TLFIELD(Type, Label, Var),
        {xmlelement, "field", [{"type", Type},
                               {"label", translate:translate(Lang, Label)},
@@ -541,7 +547,7 @@ filter_fields([], Match, _LServer) ->
     Match;
 filter_fields([{SVar, [Val]} | Ds], Match, LServer)
   when is_list(Val) and (Val /= "") ->
-    LVal = string:to_lower(Val),
+    LVal = string2lower(Val),
     NewMatch = case SVar of
                    "user" ->
                       case gen_mod:get_module_opt(LServer, ?MODULE,
@@ -618,17 +624,17 @@ set_vcard_t(R, _) ->
     OrgUnit  = xml:get_path_s(VCARD, [{elem, "ORG"}, {elem, "ORGUNIT"}, cdata]),
 
     {LUser, _LServer} = US,
-    LFN       = string:to_lower(FN),
-    LFamily   = string:to_lower(Family),
-    LGiven    = string:to_lower(Given),
-    LMiddle   = string:to_lower(Middle),
-    LNickname = string:to_lower(Nickname),
-    LBDay     = string:to_lower(BDay),
-    LCTRY     = string:to_lower(CTRY),
-    LLocality = string:to_lower(Locality),
-    LEMail    = string:to_lower(EMail),
-    LOrgName  = string:to_lower(OrgName),
-    LOrgUnit  = string:to_lower(OrgUnit),
+    LFN       = string2lower(FN),
+    LFamily   = string2lower(Family),
+    LGiven    = string2lower(Given),
+    LMiddle   = string2lower(Middle),
+    LNickname = string2lower(Nickname),
+    LBDay     = string2lower(BDay),
+    LCTRY     = string2lower(CTRY),
+    LLocality = string2lower(Locality),
+    LEMail    = string2lower(EMail),
+    LOrgName  = string2lower(OrgName),
+    LOrgUnit  = string2lower(OrgUnit),
 
     if
        (LUser     == error) or
index a4c23624c310fa1134b501ff81504cd999357857..fd1ca9022295b6cb6e7356c9f8158c23c02d83ce 100644 (file)
@@ -186,17 +186,17 @@ set_vcard(User, LServer, VCARD) ->
            end,
 
     LUser     = jlib:nodeprep(User),
-    LFN       = string:to_lower(FN),
-    LFamily   = string:to_lower(Family),
-    LGiven    = string:to_lower(Given),
-    LMiddle   = string:to_lower(Middle),
-    LNickname = string:to_lower(Nickname),
-    LBDay     = string:to_lower(BDay),
-    LCTRY     = string:to_lower(CTRY),
-    LLocality = string:to_lower(Locality),
-    LEMail    = string:to_lower(EMail),
-    LOrgName  = string:to_lower(OrgName),
-    LOrgUnit  = string:to_lower(OrgUnit),
+    LFN       = string2lower(FN),
+    LFamily   = string2lower(Family),
+    LGiven    = string2lower(Given),
+    LMiddle   = string2lower(Middle),
+    LNickname = string2lower(Nickname),
+    LBDay     = string2lower(BDay),
+    LCTRY     = string2lower(CTRY),
+    LLocality = string2lower(Locality),
+    LEMail    = string2lower(EMail),
+    LOrgName  = string2lower(OrgName),
+    LOrgUnit  = string2lower(OrgUnit),
 
     if
        (LUser     == error) or
@@ -252,6 +252,12 @@ set_vcard(User, LServer, VCARD) ->
            ejabberd_hooks:run(vcard_set, LServer, [LUser, LServer, VCARD])
     end.
 
+string2lower(String) ->
+    case stringprep:tolower(String) of
+       Lower when is_list(Lower) -> Lower;
+       error -> string:to_lower(String)
+    end.
+
 -define(TLFIELD(Type, Label, Var),
        {xmlelement, "field", [{"type", Type},
                               {"label", translate:translate(Lang, Label)},
@@ -531,7 +537,7 @@ filter_fields([], Match, _LServer) ->
     end;
 filter_fields([{SVar, [Val]} | Ds], Match, LServer)
   when is_list(Val) and (Val /= "") ->
-    LVal = string:to_lower(Val),
+    LVal = string2lower(Val),
     NewMatch = case SVar of
                    "user"     -> make_val(Match, "lusername", LVal);
                    "fn"       -> make_val(Match, "lfn",       LVal);