Permalink
Browse files

Pack up the payload instead of just appending it

When converting the notification to binary we were previously packing
everything and then tacking the notification onto the end of the
binary string with normal string concatenation, which was causing weird
encoding issues. This Fixes it by packing the payload along with
the rest of the notification. Fixes #16
  • Loading branch information...
vanstee
vanstee committed Jul 27, 2012
1 parent 59e3cac commit cbf0182a7ed2cfd5c9f896a4cfd62e2202da1b8d
Showing with 16 additions and 1 deletion.
  1. +9 −1 lib/grocer/notification.rb
  2. +7 −0 spec/grocer/notification_spec.rb
View
@@ -18,7 +18,15 @@ def to_bytes
validate_payload
payload = encoded_payload
- [1, identifier, expiry_epoch_time, device_token_length, sanitized_device_token, payload.length].pack('CNNnH64n') << payload
+ [
+ 1,
+ identifier,
+ expiry_epoch_time,
+ device_token_length,
+ sanitized_device_token,
+ payload.length,
+ payload
+ ].pack('CNNnH64nA*')
end
private
@@ -1,3 +1,5 @@
+# encoding: UTF-8
+
require 'spec_helper'
require 'grocer/notification'
@@ -71,6 +73,11 @@
payload_dictionary_from_bytes[:foo].should == 'bar'
end
+ it 'encodes UTF-8 characters to binary correctly' do
+ notification.alert = '私のホバークラフトは鰻でいっぱいです。'
+ notification.to_bytes.encoding.name.should == 'ASCII-8BIT' # binary
+ end
+
context 'invalid payload' do
let(:payload_options) { Hash.new }

0 comments on commit cbf0182

Please sign in to comment.