muthuraja3e / gcm

Automatically exported from code.google.com/p/gcm
Apache License 2.0
0 stars 0 forks source link

Incosistent encoding of data in push-to-one-device vs push-to-multiple-devices #22

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
It seems that:

a) In case of pushing a notification to a single device, i.e. 
com.google.android.gcm.server.Sender#send(Message message, String 
registrationId, int retries), the data parts get UTF-8 encoded through the 
following piece of code:
--------------------------------------------------
  public Result sendNoRetry(Message message, String registrationId)
      throws IOException {
...
    for (Entry<String, String> entry : message.getData().entrySet()) {
      String key = PARAM_PAYLOAD_PREFIX + entry.getKey();
      String value = entry.getValue();
      addParameter(body, key, URLEncoder.encode(value, UTF8));
    }
...
}
--------------------------------------------------

b) But in case of pushing a notification to multiple devices, i.e, 
com.google.android.gcm.server.Sender#send(Message message, List<String> regIds, 
int retries), such UTF-8 encoding is not applied:

--------------------------------------------------
public MulticastResult sendNoRetry(Message message,
      List<String> registrationIds) throws IOException {
...
    Map<String, String> payload = message.getData();
    if (!payload.isEmpty()) {
      jsonRequest.put(JSON_PAYLOAD, payload);
    }
...
}
--------------------------------------------------

Shouldn't the handling of 2 cases be consistent? Or, in the 2nd case, is it 
assumed to be the application programmer's responsibility to UTF-8 encode? If 
yes, a note in the documentation may make sense.

Original issue reported on code.google.com by roshanda...@gmail.com on 5 May 2013 at 7:15

GoogleCodeExporter commented 9 years ago
You can find the fix for this bug in issue #17

Original comment by KurtHu...@gmail.com on 25 Aug 2014 at 9:15

GoogleCodeExporter commented 9 years ago
You can find a repo with the fix of issue #17 here:

https://github.com/kurthuwig/gcm/commit/d37f4d1c37ed8deaf1a161ca7b881c1d843f80df

Original comment by KurtHu...@gmail.com on 25 Aug 2014 at 9:39