You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Yoshihiro Tanaka (JIRA)" <ji...@apache.org> on 2013/07/10 06:35:52 UTC

[jira] [Closed] (THRIFT-2077) Erlang Thrift library does not handle unicode string values

     [ https://issues.apache.org/jira/browse/THRIFT-2077?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Yoshihiro Tanaka closed THRIFT-2077.
------------------------------------

    Resolution: Invalid
    
> Erlang Thrift library does not handle unicode string values
> -----------------------------------------------------------
>
>                 Key: THRIFT-2077
>                 URL: https://issues.apache.org/jira/browse/THRIFT-2077
>             Project: Thrift
>          Issue Type: Bug
>          Components: Erlang - Library
>    Affects Versions: 0.9
>         Environment: R15B03 or before
>            Reporter: Yoshihiro Tanaka
>         Attachments: thrift-2077-erl-unicode-error.patch
>
>
> When callback function returns unicode string, thrift server crashes with following code:
> {noformat}
> -module(mysample_thrift_service).
> -include ("mysample_thrift.hrl").
> -export([ start_link/0,
>           stop/1,
>           handle_function/2,
>           handle_error/2,
>           check_val/1,
>           send_req/1
>          ]).
> start_link () ->
>   Options = [ {port, 1234},
>               {name, ?MODULE},
>               {framed,true},
>               {service, mysample_thrift},
>               {handler, ?MODULE},
>               {socket_opts, [{recv_timeout, 60*60*1000}]}
>             ],
>   thrift_socket_server:start (Options).
> stop (Server) ->
>   thrift_socket_server:stop (Server),
>   ok.
> handle_function (Function, Args) when is_atom(Function), is_tuple(Args) ->
>   case apply (?MODULE, Function, tuple_to_list(Args)) of
>     ok -> ok;
>     Reply -> {reply, Reply}
>   end.
> handle_error (_, closed) -> ok;
> handle_error (Function, Reason) ->
>   io:format ("Error Function:~p, Reason:~p~n", [Function, Reason]).
> check_val (Val = <<"ascii string">>) ->
>   binary_to_list (Val);
> check_val (Val = <<"unicode">>) ->
>   binary_to_list (Val) ++ [8220,98,97,100,8221];
> check_val (Val) ->
>   "ok_string".
> send_req(Val) ->
>   {ok,Client0} = thrift_client_util:new(
>                    localhost, 1234, mysample_thrift, [{framed,true}]
>                  ),
>   {Client1,{ok,Result}} = thrift_client:call(Client0,check_val,[Val]),
>   thrift_client:close(Client1),
>   {ok, Result}.
> {noformat}
> The error looks as following:
> {noformat}
> 2> mysample_thrift_service:send_req("unicode").
> =ERROR REPORT==== 29-Jun-2013::22:06:25 ===
> check_val had an error: {badarg,
>                             [{erlang,list_to_binary,
>                                  [[117,110,105,99,111,100,101,8220,98,97,100,
>                                    8221]],
>                                  []},
>                              {thrift_binary_protocol,write,2,
>                                  [{file,"thrift_binary_protocol.erl"},
>                                   {line,159}]},
>                              {thrift_protocol,write,2,
>                                  [{file,"thrift_protocol.erl"},{line,389}]},
>                              {thrift_protocol,struct_write_loop,3,
>                                  [{file,"thrift_protocol.erl"},{line,402}]},
>                              {thrift_protocol,write,2,
>                                  [{file,"thrift_protocol.erl"},{line,322}]},
>                              {thrift_processor,send_reply,5,
>                                  [{file,"src/thrift_processor.erl"},
>                                   {line,200}]},
>                              {thrift_processor,handle_function,3,
>                                  [{file,"src/thrift_processor.erl"},
>                                   {line,90}]},
>                              {thrift_processor,loop,1,
>                                  [{file,"src/thrift_processor.erl"},
>                                   {line,43}]}]}
> {noformat}
> I tried to fix using 'unicode:characters_to_binary/3', but it did not work.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira