Permalink
Browse files

support (and enforce) utf-8 charset

  • Loading branch information...
1 parent 0d1b86a commit 4447f32082d713923aa2ced82c673c1dba1b7ff0 @beerriot beerriot committed Oct 5, 2010
@@ -28,7 +28,7 @@
while 1:
L = sys.stdin.readline()
if L.strip() == COMMAND_BREAK:
- H = creoleparser.text2html(Acc)
+ H = creoleparser.text2html(Acc.decode('utf-8'))
print H
print COMMAND_BREAK
sys.stdout.flush()
@@ -29,13 +29,18 @@ function articleURL() {
return L.slice(0, L.indexOf('?'));
}
+function decode_utf8(string) {
+ return decodeURIComponent(escape(string));
+}
+
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
- if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
+ if (c.indexOf(nameEQ) == 0)
+ return decode_utf8(c.substring(nameEQ.length,c.length));
}
return null;
}
@@ -20,12 +20,16 @@
-module(login_form_resource).
-export([init/1,
+ charsets_provided/2,
to_html/2,
return_location/1]).
-include_lib("webmachine/include/webmachine.hrl").
init([]) -> {ok, nostate}.
+charsets_provided(RD, Ctx) ->
+ {[{"utf-8", fun(C) -> C end}], RD, Ctx}.
+
to_html(RD, Ctx) ->
{ok, C} = login_form_dtl:render([{req, wrq_dtl_helper:new(RD)},
{username, ""}]),
@@ -24,6 +24,7 @@
expires/2,
resource_exists/2,
content_types_provided/2,
+ charsets_provided/2,
to_json/2,
delete_resource/2]).
-include_lib("webmachine/include/webmachine.hrl").
@@ -46,7 +47,8 @@ resource_exists(RD, Ctx=#ctx{client=C}) ->
case session:fetch(C, list_to_binary(wrq:path_info(session, RD))) of
{ok, Session} ->
case session:get_user(Session) ==
- list_to_binary(wrq:path_info(name, RD)) of
+ list_to_binary(
+ mochiweb_util:unquote(wrq:path_info(name, RD))) of
true ->
{ok, SC} = wrc:set_client_id(C, wobj:key(Session)),
NewSession = session:refresh(Session),
@@ -62,6 +64,9 @@ resource_exists(RD, Ctx=#ctx{client=C}) ->
content_types_provided(RD, Ctx) ->
{[{"application/json", to_json}], RD, Ctx}.
+charsets_provided(RD, Ctx) ->
+ {[{"utf-8", fun(C) -> C end}], RD, Ctx}.
+
to_json(RD, Ctx=#ctx{session=Session}) ->
{mochijson2:encode(
{struct, [{<<"expiry">>, session:get_expiry(Session)}]}),
@@ -30,6 +30,7 @@
allowed_methods/2,
content_types_accepted/2,
resource_exists/2,
+ charsets_provided/2,
is_authorized/2,
to_html/2,
is_conflict/2,
@@ -54,6 +55,9 @@ init([]) ->
allowed_methods(RD, Ctx) ->
{['HEAD','GET','PUT','POST'],RD,Ctx}.
+charsets_provided(RD, Ctx) ->
+ {[{"utf-8", fun(C) -> C end}], RD, Ctx}.
+
content_types_accepted(RD, Ctx) ->
{[{"application/x-www-form-urlencoded", accept_form}], RD, Ctx}.
@@ -176,7 +180,7 @@ lookup_user(RD, Ctx=#ctx{user=undefined, client=Client}) ->
lookup_user(_, Ctx) -> Ctx. %% already looked up
username(RD) ->
- list_to_binary(wrq:path_info(name, RD)).
+ list_to_binary(mochiweb_util:unquote(wrq:path_info(name, RD))).
edit_mode(RD) ->
wrq:get_qs_value("edit", RD) /= undefined.
@@ -189,7 +193,7 @@ finish_request(RD, Ctx) ->
{req, wrq_dtl_helper:new(RD)}]),
{true,
wrq:set_resp_header(
- "Content-type", "text/html",
+ "Content-type", "text/html; charset=utf-8",
wrq:set_resp_body(Content, RD)),
Ctx};
_ ->
@@ -21,6 +21,7 @@
-export([init/1,
is_authorized/2,
resource_exists/2,
+ charsets_provided/2,
to_html/2,
allowed_methods/2,
content_types_accepted/2,
@@ -52,6 +53,9 @@ init([]) ->
allowed_methods(RD, Ctx) ->
{['HEAD','GET','POST','PUT'], RD, Ctx}.
+charsets_provided(RD, Ctx) ->
+ {[{"utf-8", fun(C) -> C end}], RD, Ctx}.
+
content_types_accepted(RD, Ctx) ->
{[{"application/x-www-form-urlencoded", accept_form}], RD, Ctx}.
@@ -221,7 +225,7 @@ finish_request(RD, Ctx) ->
end,
{true,
wrq:set_resp_header(
- "Content-type", "text/html",
+ "Content-type", "text/html; charset=utf-8",
wrq:set_resp_body(Content, NewRD)),
NewCtx};
_ ->
@@ -232,8 +236,7 @@ render_404_editor(RD, Ctx) ->
Article = article:create(search_path(RD),
list_to_binary(
[<<"= This page describes ">>,
- mochiweb_html:escape(
- base64url:decode_to_string(search_path(RD))),
+ base64url:decode_to_string(search_path(RD)),
<<" =\n">>]),
<<>>,
undefined,

0 comments on commit 4447f32

Please sign in to comment.