Skip to content

Push messages encoding issue #35

masterkain opened this Issue Apr 18, 2012 · 10 comments

3 participants


I'm using Ruby 1.9.3-p125, Slanger master.

I'm sending this event to Slanger from my Rails app, this is from my log:

 [PUSH] Sending event <media_update> to channel <private-b42c45b11e17ec477df247fc6fdccba122a91028> with payload <{:media_file=>{:album=>"Mit Raben Und Wölfen"}}> 

Slanger's log of this message:

   "{\"event\":\"media_update\",\"data\":\"{\\\"media_file\\\":{\\\"album\\\":\\\"Mit Raben Und W\\ufffd\\ufffdlfen\\\"}\",\"channel\":\"private-b42c45b11e17ec477df247fc6fdccba122a91028\"}"]]

Now this is causing an issue, because when I print what I got from Slanger in the web page I get this string:

"Mit Raben Und W��lfen"

At the moment I'm not able to print properly in the web page the content of a push message due to this issue, do you have any hints or it's something within slanger/pusher.js?


Apparently the message is going into redis already with those special chars:

Since Slanger uses activesupport and multi_json I tried to include yajl in my Gemfile in the hope to switch encoder but the problem is still present. Investigating.


I'm able to fix this issue by using directly yajl in api_server.rb during the compilation of payload:

Yajl::Encoder.encode(Hash[payload.reject { |k,v| v.nil? }])

I changed the gem code to take advantage of MultiJson so one can pickup the best json gem. This does resolve the issue.



This sounds like it's a good idea if it fixes the encoding issues you mention.

I've tried merging your fork in against master and non of the tests pass I'm getting the following:

/Users/mark/Sites/slanger/lib/slanger/handler.rb:160:in `payload': undefined method `dump' for MultiJson:Module (NoMethodError)
    from /Users/mark/Sites/slanger/lib/slanger/handler.rb:87:in `send_payload'
    from /Users/mark/Sites/slanger/lib/slanger/handler.rb:62:in `authenticate'
    from /Users/mark/Sites/slanger/lib/slanger/handler.rb:15:in `initialize'
    from /Users/mark/Sites/slanger/lib/slanger/web_socket_server.rb:24:in `new'
    from /Users/mark/Sites/slanger/lib/slanger/web_socket_server.rb:24:in `block (3 levels) in run'
    from /Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/em-websocket-0.3.5/lib/em-websocket/connection.rb:18:in `call'
    from /Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/em-websocket-0.3.5/lib/em-websocket/connection.rb:18:in `trigger_on_open'
    from /Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/em-websocket-0.3.5/lib/em-websocket/handler.rb:18:in `run'
    from /Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/em-websocket-0.3.5/lib/em-websocket/connection.rb:106:in `dispatch'
    from /Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/em-websocket-0.3.5/lib/em-websocket/connection.rb:63:in `receive_data'
    from /Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run_machine'
    from /Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run'
    from /Users/mark/.rvm/gems/ruby-1.9.3-p125/gems/eventmachine-0.12.10/lib/eventmachine.rb:329:in `block in fork


Yeah sorry, I still have to update the specs to use MultiJson. I'll try to find time do it later today, but if you want to go ahead be my guest :)


Just having a look. Not sure what the problem is. Any pointers for

undefined method `dump' for MultiJson:Module


Missing a require or something? Is this working stand alone for you, or is it part of an app that requires something first?


Currently it's working standalone for me, my Gemfile:

source ''

gem 'yajl-ruby', :require => 'yajl' # JSON
#gem 'slanger', git: 'git://'
gem 'slanger', git: 'git://'
gem 'em-websocket', git: 'git://'
#gem 'em-websocket', git: 'git://'

gem 'foreman', require: false

group :development do
  gem 'capistrano'
  gem 'capistrano-ext'

MultiJson just changed method naming, you might want to check that but I believe they kept the old ones around for compat anyway; I'm not sure what the problem is at the moment. Perhaps are you using an old version?


Also check out this commit: masterkain@f320ce8

You said you tried to merge the tree so I didn't mention this other commit.


And the Gemfile.lock:


OK, no dice. Not sure what your gem file is if you said it's working standalone. I guess this is an app you're using it from?
Not sure which of the dependencies is the correct one to pull in. I merged your fork into my local master which did pull in the require 'multijson'.

If you can get your fork working and create a pull request there's more chance of getting it merged in.
Also would be good to see a failing test without MultiJSON and a passing one with it.


Does Encoding.default_external = "utf-8" fix this? Can we have a test also?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.