Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixing issue #57 on JSONP escaping problems

By using JSX's format function and proper encoding/decoding
the number of slashes is reduced to something reasonable
that seems to work across the board.
  • Loading branch information...
commit a1467789714a9979adb26b8a6d25d501370e47b7 1 parent e6d144a
@ferd ferd authored
Showing with 24 additions and 2 deletions.
  1. +23 −1 demo/demo.erl
  2. +1 −1  src/socketio_transport_polling.erl
View
24 demo/demo.erl
@@ -32,8 +32,30 @@ handle_event({disconnect, Pid}, State) ->
{ok, State};
handle_event({message, Client, #msg{ content = Content } = Msg}, State) ->
io:format("Got a message: ~p from ~p~n",[Msg, Client]),
+ Struct = [[{<<"action">>,<<"feedback">>},
+ {<<"payload">>,
+ [{<<"context">>,<<"order_ack">>},
+ {<<"report_id">>,90},
+ {<<"report_type">>,<<"new">>},
+ {<<"order_id">>,76},
+ {<<"user_id">>,<<"stig">>},
+ {<<"client_order_id">>,6},
+ {<<"client_head_id">>,6},
+ {<<"order_type">>,<<"new">>},
+ {<<"status">>,<<"new">>},
+ {<<"fill_type">>,<<"day">>},
+ {<<"book_id">>,<<"usd_rate_outright_2">>},
+ {<<"side">>,<<"bid">>},
+ {<<"price">>,9000},
+ {<<"order_qty">>,120},
+ {<<"head_qty">>,120},
+ {<<"display_qty">>,<<"undefined">>},
+ {<<"fill_qty">>,0},
+ {<<"left_qty">>,120},
+ {<<"child_id">>,<<"undefined">>},
+ {<<"head_id">>,76}]}]],
socketio_client:send(Client, #msg{ content = "hello!" }),
- socketio_client:send(Client, #msg{ content = [{<<"echo">>, Content}], json = true}),
+ socketio_client:send(Client, #msg{ content = Struct, json = true}),
{ok, State};
handle_event(E, State) ->
View
2  src/socketio_transport_polling.erl
@@ -296,7 +296,7 @@ send_message(Message, Req, Index, ServerModule, Sup) ->
send_message_1(Headers, Message, Req, Index, ServerModule) ->
Headers0 = [{"Content-Type", "text/javascript; charset=UTF-8"}|Headers],
- Message0 = binary_to_list(jsx:term_to_json(list_to_binary(Message), [{strict, false}])),
+ Message0 = unicode:characters_to_list(jsx:format(jsx:term_to_json(list_to_binary(Message), [{strict, false}]))),
Message1 = "io.JSONP["++Index++"]._(" ++ Message0 ++ ");",
apply(ServerModule, respond, [Req, 200, Headers0, Message1]).
Please sign in to comment.
Something went wrong with that request. Please try again.