Skip to content
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...
1 parent 59e3cac commit cbf0182a7ed2cfd5c9f896a4cfd62e2202da1b8d @vanstee vanstee committed
Showing with 16 additions and 1 deletion.
  1. +9 −1 lib/grocer/notification.rb
  2. +7 −0 spec/grocer/notification_spec.rb
View
10 lib/grocer/notification.rb
@@ -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
View
7 spec/grocer/notification_spec.rb
@@ -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.
Something went wrong with that request. Please try again.