From 112a18f966b0fa8525d8638e38adec88d048dedb Mon Sep 17 00:00:00 2001 From: Badlop Date: Tue, 14 Feb 2012 13:18:18 +0100 Subject: [PATCH] Work also with some unicode strings in PgSQL (EJAB-1490) --- src/mod_vcard.erl | 52 +++++++++++++++++++++++------------------- src/mod_vcard_odbc.erl | 30 ++++++++++++++---------- 2 files changed, 47 insertions(+), 35 deletions(-) diff --git a/src/mod_vcard.erl b/src/mod_vcard.erl index 1820f64b8..46830b020 100644 --- a/src/mod_vcard.erl +++ b/src/mod_vcard.erl @@ -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 diff --git a/src/mod_vcard_odbc.erl b/src/mod_vcard_odbc.erl index a4c23624c..fd1ca9022 100644 --- a/src/mod_vcard_odbc.erl +++ b/src/mod_vcard_odbc.erl @@ -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);