Skip to content
Browse files

quick fix for request charset decode

  • Loading branch information...
1 parent df8ba88 commit 11e34bac06cd553cc1856304e7168efe25bff662 jackyz committed Oct 8, 2010
View
3 lib/eptic-1.4.1/src/e_json.erl
@@ -118,6 +118,9 @@ string_to_json_string([34|T], Acc) -> % $"
string_to_json_string(T, [34,$\\|Acc]);
string_to_json_string([$ |T], Acc) ->
string_to_json_string(T, [$ |Acc]);
+%% process unicode % or map to something like \uxxxx, not sure
+string_to_json_string([H|T], Acc) when H > 256 ->
+ string_to_json_string(T, [binary_to_list(unicode:characters_to_binary([H]))|Acc]);
string_to_json_string([H|T], Acc) ->
string_to_json_string(T, [H|Acc]).
View
28 lib/eptic-1.4.1/src/e_mod_inets.erl
@@ -192,31 +192,29 @@ create_headers([_ | Rest], Acc) ->
%% @hidden
-spec(parse_get/1 :: (string()) -> list(tuple())).
parse_get(URL) ->
- case string:chr(URL, $?) of
- 0 ->
- [];
- Pos ->
- Get = string:tokens(string:sub_string(URL, Pos+1), [$&]),
- lists:map(fun(Pair) ->
- case string:tokens(Pair, [$=]) of
- [Key, Val] ->
- {Key, Val};
- [Key | _] ->
- {Key, ""}
- end
- end, Get)
- end.
+ fix_charset(httpd:parse_query(URL)).
-spec(parse_post/1 :: (string()) -> list(tuple())).
parse_post(String) ->
case fetch_boundary(String) of
{simple, Data} ->
- httpd:parse_query(Data);
+ fix_charset(httpd:parse_query(Data));
{multipart, Boundary} ->
e_multipart_inets:get_multipart(String, Boundary)
end.
%% @hidden
+%% this is a quick and dirty fix, the total solution should based on
+%% "content-type=xxx;charset=yyy" property in request http header but
+%% for now, erlang only has unicode/utf8 charset decoder, so...
+-spec(fix_charset/1 :: (list(tuple())) -> list(tuple())).
+fix_charset(In) ->
+ lists:map(fun
+ ({Key, Val}) ->
+ {Key, unicode:characters_to_list(list_to_binary(Val))}
+ end, In).
+
+%% @hidden
-spec(fetch_boundary/1 :: (string()) -> {simple, string()} | {multipart, string()}).
fetch_boundary(Data) ->
case string:str(Data, "\r\n") of
View
2 lib/wpart-1.4.1/src/wpart_xs.erl
@@ -42,7 +42,7 @@ doctype()->
%% @hidden
-spec(template/1 :: (tuple() | list(tuple())) -> list(string()) | string()).
template(#xmlElement{name = 'html'} = E) ->
- ["<?xml version=\"1.0\" encoding=\"utf-8\"?>\n",
+ [ %% "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n", %% buggy ie6
doctype(),
"<html xmlns=\"http://www.w3.org/1999/xhtml\">\n",
xslapply(fun template/1, E),
View
13 lib/wparts-1.4.1/src/wtype_password.erl
@@ -45,13 +45,12 @@ validate({Types, undefined}) ->
end
end;
-validate({Types, [RawString1, RawString2]})
- when is_list(RawString1) and is_list(RawString2) ->
- validate2({Types, [utf8_api:ustring(RawString1),
- utf8_api:ustring(RawString2)]});
+validate({Types, [String1, String2]})
+ when is_list(String1) and is_list(String2) ->
+ validate2({Types, [String1, String2]});
-validate({Types, RawString}) when is_list(RawString) ->
- validate2({Types, utf8_api:ustring(RawString)}).
+validate({Types, String}) when is_list(String) ->
+ validate2({Types, String}).
validate2({Types, String}) when is_list(String) ->
case wpart_valid:is_private(Types) of
@@ -116,7 +115,7 @@ check_max_length(String, Types) ->
check_regexp(String, Types) ->
case lists:keysearch(regexp, 1, Types) of
{value, {regexp, Regexp}} ->
- case re:run(String, Regexp) of
+ case re:run(String, Regexp, [unicode]) of
{match, _} ->
{ok, String};
nomatch ->
View
22 lib/wparts-1.4.1/src/wtype_string.erl
@@ -56,14 +56,14 @@ validate({Types,String}) when is_list(String) ->
{ok, String} ->
case check_regexp(String, Types) of
{ok, String} ->
- case check_html(String, Types) of
- {ok, S} ->
- {ok, unicode:characters_to_list(list_to_binary(S))};
- Err ->
- Err
- end;
- ErrorRegexp ->
- ErrorRegexp
+ case check_html(String, Types) of
+ {ok, _} ->
+ {ok, String};
+ Err ->
+ Err
+ end;
+ ErrorRegexp ->
+ ErrorRegexp
end;
ErrorMax ->
ErrorMax
@@ -76,7 +76,7 @@ validate({Types,String}) when is_list(String) ->
check_min_length(String, Types) ->
case lists:keysearch(min_length, 1, Types) of
{value, {min_length, Min}} ->
- N = utf8_api:ulength(String),
+ N = length(String),
if
N < Min ->
{error, {too_short, String}};
@@ -90,7 +90,7 @@ check_min_length(String, Types) ->
check_max_length(String, Types) ->
case lists:keysearch(max_length, 1, Types) of
{value, {max_length, Max}} ->
- N = utf8_api:ulength(String),
+ N = length(String),
if
N > Max ->
{error, {too_long, String}};
@@ -104,7 +104,7 @@ check_max_length(String, Types) ->
check_regexp(String, Types) ->
case lists:keysearch(regexp, 1, Types) of
{value, {regexp, Regexp}} ->
- case re:run(String, Regexp) of
+ case re:run(String, Regexp, [unicode]) of
{match, _} ->
{ok, String};
nomatch ->
View
8 lib/wparts-1.4.1/src/wtype_text.erl
@@ -53,8 +53,8 @@ validate({Types,Text}) when is_list(Text) ->
case check_max_length(Text, Types) of
{ok, Text} ->
case check_html(Text, Types) of
- {ok, S} ->
- {ok, unicode:characters_to_list(list_to_binary(S))};
+ {ok, _} ->
+ {ok, Text};
Err ->
Err
end;
@@ -75,7 +75,7 @@ validate({Types, Text}) ->
check_min_length(String, Types) ->
case lists:keysearch(min_length, 1, Types) of
{value, {min_length, Min}} ->
- X = utf8_api:ulength(String),
+ X = length(String),
if
X < Min ->
{error, {too_short, String}};
@@ -89,7 +89,7 @@ check_min_length(String, Types) ->
check_max_length(String, Types) ->
case lists:keysearch(max_length, 1, Types) of
{value, {max_length, Max}} ->
- X = utf8_api:ulength(String),
+ X = length(String),
if
X > Max ->
{error, {too_long, String}};

0 comments on commit 11e34ba

Please sign in to comment.
Something went wrong with that request. Please try again.