Commits

Anonymous committed eb57f9c

support (and enforce) utf-8 charset

Comments (0)

Files changed (6)

apps/wiki_creole/priv/creole_worker.py

 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()

apps/wriaki/priv/www/js/wriaki.js

     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;
 }

apps/wriaki/src/login_form_resource.erl

 -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, ""}]),

apps/wriaki/src/session_resource.erl

          expires/2,
          resource_exists/2,
          content_types_provided/2,
+         charsets_provided/2,
          to_json/2,
          delete_resource/2]).
 -include_lib("webmachine/include/webmachine.hrl").
     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),
 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)}]}),

apps/wriaki/src/user_resource.erl

          allowed_methods/2,
          content_types_accepted/2,
          resource_exists/2,
+         charsets_provided/2,
          is_authorized/2,
          to_html/2,
          is_conflict/2,
 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}.
 
 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.
                                {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};
         _ ->

apps/wriaki/src/wiki_resource.erl

 -export([init/1,
          is_authorized/2,
          resource_exists/2,
+         charsets_provided/2,
          to_html/2,
          allowed_methods/2,
          content_types_accepted/2,
 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}.
 
                 end,
             {true,
              wrq:set_resp_header(
-               "Content-type", "text/html",
+               "Content-type", "text/html; charset=utf-8",
                wrq:set_resp_body(Content, NewRD)),
              NewCtx};
         _ ->
     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,