Skip to content
This repository
Browse code

Merge branch 'master' of github.com:esl/erlang-web

  • Loading branch information...
commit 155561afd19679e7756be5cfecfbb42f58660f9a 2 parents 34f3431 + 81b3c31
Roberto Aloi authored January 13, 2011
3  lib/eptic-1.4.1/src/e_json.erl
@@ -118,6 +118,9 @@ string_to_json_string([34|T], Acc) -> % $"
118 118
     string_to_json_string(T, [34,$\\|Acc]);
119 119
 string_to_json_string([$ |T], Acc) ->
120 120
     string_to_json_string(T, [$ |Acc]);
  121
+%% process unicode % or map to something like \uxxxx, not sure
  122
+string_to_json_string([H|T], Acc) when H > 256 -> 
  123
+    string_to_json_string(T, [binary_to_list(unicode:characters_to_binary([H]))|Acc]);
121 124
 string_to_json_string([H|T], Acc) ->
122 125
     string_to_json_string(T, [H|Acc]).
123 126
 
28  lib/eptic-1.4.1/src/e_mod_inets.erl
@@ -192,31 +192,29 @@ create_headers([_ | Rest], Acc) ->
192 192
 %% @hidden
193 193
 -spec(parse_get/1 :: (string()) -> list(tuple())).	     
194 194
 parse_get(URL) ->
195  
-    case string:chr(URL, $?) of
196  
-	0 ->
197  
-	    [];
198  
-	Pos ->
199  
-	    Get = string:tokens(string:sub_string(URL, Pos+1), [$&]),
200  
-	    lists:map(fun(Pair) ->
201  
-			      case string:tokens(Pair, [$=]) of
202  
-				  [Key, Val] ->
203  
-				      {Key, Val};
204  
-				  [Key | _] ->
205  
-				      {Key, ""}
206  
-			      end
207  
-		      end, Get)
208  
-    end.
  195
+    fix_charset(httpd:parse_query(URL)).
209 196
 
210 197
 -spec(parse_post/1 :: (string()) -> list(tuple())).	     
211 198
 parse_post(String) ->
212 199
     case fetch_boundary(String) of
213 200
 	{simple, Data} ->
214  
-	    httpd:parse_query(Data);
  201
+	    fix_charset(httpd:parse_query(Data));
215 202
 	{multipart, Boundary} ->
216 203
 	    e_multipart_inets:get_multipart(String, Boundary)
217 204
     end.
218 205
 
219 206
 %% @hidden
  207
+%% this is a quick and dirty fix, the total solution should based on 
  208
+%% "content-type=xxx;charset=yyy" property in request http header but 
  209
+%% for now, erlang only has unicode/utf8 charset decoder, so...
  210
+-spec(fix_charset/1 :: (list(tuple())) -> list(tuple())).
  211
+fix_charset(In) ->
  212
+    lists:map(fun
  213
+		  ({Key, Val}) ->
  214
+		      {Key, unicode:characters_to_list(list_to_binary(Val))}
  215
+	      end, In).
  216
+
  217
+%% @hidden
220 218
 -spec(fetch_boundary/1 :: (string()) -> {simple, string()} | {multipart, string()}).	     
221 219
 fetch_boundary(Data) ->
222 220
     case string:str(Data, "\r\n") of
10  lib/eptic-1.4.1/src/e_multipart_inets.erl
@@ -30,7 +30,7 @@
30 30
 
31 31
 get_multipart(Body, Boundary) ->
32 32
     Regexp = Boundary ++ "((\r\n)|(\-\-\r\n))",
33  
-    {ok, Split} = regexp:split(Body, Regexp),
  33
+    {ok, Split} = re:split(Body, Regexp),
34 34
     retrive_data(Split).
35 35
 
36 36
 terminate() ->
@@ -48,11 +48,11 @@ retrive_data([]) ->
48 48
 retrive_data([[] | Rest]) ->
49 49
     retrive_data(Rest);
50 50
 retrive_data(["Content-Disposition: form-data; " ++ Element | Rest]) ->
51  
-    {match, HeaderStart, HeaderLen} = regexp:first_match(Element, ".*\r\n"),
  51
+    {match, HeaderStart, HeaderLen} = re:first_match(Element, ".*\r\n"),
52 52
     HeaderString = string:substr(Element, HeaderStart, HeaderLen-2),
53  
-    {ok, Fields} = regexp:split(HeaderString, "; "),
  53
+    {ok, Fields} = re:split(HeaderString, "; "),
54 54
     Header = lists:foldl(fun(E, Acc) ->
55  
-				 {ok, [Key, Value]} = regexp:split(E, "="),
  55
+				 {ok, [Key, Value]} = re:split(E, "="),
56 56
 				 [{list_to_atom(Key), Value} | Acc]
57 57
 			 end, [], Fields),
58 58
     HeaderLength = HeaderStart+HeaderLen+2,
@@ -72,7 +72,7 @@ retrive_data(["Content-Disposition: form-data; " ++ Element | Rest]) ->
72 72
 		    [{Name, []} | retrive_data(Rest)];
73 73
 		{value, {filename, SFilename}} ->
74 74
 		    Filename0 = string:strip(SFilename, both, 34),
75  
-		    Filename = case regexp:first_match(Content, "\r\n\r\n") of
  75
+		    Filename = case re:first_match(Content, "\r\n\r\n") of
76 76
 				   {match, ContentS, _} ->
77 77
 				       save_file(Filename0, string:substr(Content, ContentS+4));
78 78
 				   nomatch ->
4  lib/wpart-1.4.1/src/wpart_xs.erl
@@ -42,7 +42,7 @@ doctype()->
42 42
 %% @hidden
43 43
 -spec(template/1 :: (tuple() | list(tuple())) -> list(string()) | string()).
44 44
 template(#xmlElement{name = 'html'} = E) ->
45  
-    ["<?xml version=\"1.0\" encoding=\"utf-8\"?>\n",
  45
+    [ %% "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n", %% buggy ie6
46 46
      doctype(),
47 47
      "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n",
48 48
      xslapply(fun template/1, E),
@@ -132,7 +132,7 @@ entitify(B) ->
132 132
     entitify(B, []).
133 133
 entitify(<<>>, Acc) ->
134 134
     lists:reverse(Acc);
135  
-entitify(<<34:8, Rest/binary>>, Acc) -> % double quote (&quot);
  135
+entitify(<<34:8, Rest/binary>>, Acc) -> % double quote (&quot;)
136 136
     NewAcc = ["&#34;"|Acc],
137 137
     entitify(Rest, NewAcc);
138 138
 entitify(<<38:8, Rest/binary>>, Acc) -> % ampersand (&amp;)
13  lib/wparts-1.4.1/src/wtype_password.erl
@@ -45,13 +45,12 @@ validate({Types, undefined}) ->
45 45
             end
46 46
     end;
47 47
 
48  
-validate({Types, [RawString1, RawString2]}) 
49  
-  when is_list(RawString1) and is_list(RawString2) ->
50  
-    validate2({Types, [utf8_api:ustring(RawString1), 
51  
-                       utf8_api:ustring(RawString2)]});
  48
+validate({Types, [String1, String2]}) 
  49
+  when is_list(String1) and is_list(String2) ->
  50
+    validate2({Types, [String1, String2]});
52 51
 
53  
-validate({Types, RawString}) when is_list(RawString) ->
54  
-    validate2({Types, utf8_api:ustring(RawString)}).
  52
+validate({Types, String}) when is_list(String) ->
  53
+    validate2({Types, String}).
55 54
 
56 55
 validate2({Types, String}) when is_list(String) ->
57 56
     case wpart_valid:is_private(Types) of
@@ -116,7 +115,7 @@ check_max_length(String, Types) ->
116 115
 check_regexp(String, Types) ->
117 116
     case lists:keysearch(regexp, 1, Types) of
118 117
 	{value, {regexp, Regexp}} ->
119  
-	    case re:run(String, Regexp) of
  118
+	    case re:run(String, Regexp, [unicode]) of
120 119
 		{match, _} ->
121 120
 		    {ok, String};
122 121
 		nomatch ->
22  lib/wparts-1.4.1/src/wtype_string.erl
@@ -56,14 +56,14 @@ validate({Types,String}) when is_list(String) ->
56 56
 			{ok, String} -> 
57 57
 			    case check_regexp(String, Types) of
58 58
 					{ok, String} ->
59  
-                        case check_html(String, Types) of
60  
-                            {ok, S} ->
61  
-                                {ok, unicode:characters_to_list(list_to_binary(S))};
62  
-                            Err ->
63  
-                                Err
64  
-                        end;
65  
-					ErrorRegexp ->
66  
-				  	  ErrorRegexp
  59
+				    case check_html(String, Types) of
  60
+					{ok, _} ->
  61
+					    {ok, String};
  62
+					Err ->
  63
+					    Err
  64
+				    end;
  65
+				ErrorRegexp ->
  66
+				    ErrorRegexp
67 67
 			    end;
68 68
 			ErrorMax -> 
69 69
 			    ErrorMax
@@ -76,7 +76,7 @@ validate({Types,String}) when is_list(String) ->
76 76
 check_min_length(String, Types) ->
77 77
     case lists:keysearch(min_length, 1, Types) of
78 78
 	{value, {min_length, Min}} ->
79  
-            N = utf8_api:ulength(String),
  79
+            N = length(String),
80 80
     	    if
81 81
 		N < Min ->
82 82
 		    {error, {too_short, String}};
@@ -90,7 +90,7 @@ check_min_length(String, Types) ->
90 90
 check_max_length(String, Types) ->
91 91
     case lists:keysearch(max_length, 1, Types) of
92 92
 	{value, {max_length, Max}} ->
93  
-            N = utf8_api:ulength(String),
  93
+            N = length(String),
94 94
 	    if
95 95
 		N > Max ->
96 96
 		    {error, {too_long, String}};
@@ -104,7 +104,7 @@ check_max_length(String, Types) ->
104 104
 check_regexp(String, Types) ->
105 105
     case lists:keysearch(regexp, 1, Types) of
106 106
 	{value, {regexp, Regexp}} ->
107  
-	    case re:run(String, Regexp) of
  107
+	    case re:run(String, Regexp, [unicode]) of
108 108
 		{match, _} ->
109 109
 		    {ok, String};
110 110
 		nomatch ->
8  lib/wparts-1.4.1/src/wtype_text.erl
@@ -53,8 +53,8 @@ validate({Types,Text}) when is_list(Text) ->
53 53
 		    case check_max_length(Text, Types) of
54 54
 			{ok, Text} ->
55 55
                 case check_html(Text, Types) of
56  
-                    {ok, S} ->
57  
-                        {ok, unicode:characters_to_list(list_to_binary(S))};
  56
+                    {ok, _} ->
  57
+                        {ok, Text};
58 58
                     Err ->
59 59
                         Err
60 60
                 end;
@@ -75,7 +75,7 @@ validate({Types, Text}) ->
75 75
 check_min_length(String, Types) ->
76 76
     case lists:keysearch(min_length, 1, Types) of
77 77
 	{value, {min_length, Min}} ->
78  
-            X = utf8_api:ulength(String),
  78
+            X = length(String),
79 79
 	    if
80 80
 		 X < Min ->
81 81
 		    {error, {too_short, String}};
@@ -89,7 +89,7 @@ check_min_length(String, Types) ->
89 89
 check_max_length(String, Types) ->
90 90
     case lists:keysearch(max_length, 1, Types) of
91 91
 	{value, {max_length, Max}} ->
92  
-	    X = utf8_api:ulength(String),
  92
+	    X = length(String),
93 93
             if
94 94
 		X > Max ->
95 95
 		    {error, {too_long, String}};

0 notes on commit 155561a

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